Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check buildPath consistently #1143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/buildFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

const buildFile = require('./buildFile');
const validBuildPath = require("./utils/validBuildPath");

/**
* Takes a platform config object and a dictionary
Expand All @@ -24,7 +25,7 @@ const buildFile = require('./buildFile');
* @returns {null}
*/
function buildFiles(dictionary, platform) {
if (platform.buildPath && (platform.buildPath.slice(-1) !== '/' && platform.buildPath.slice(-1) !== '\\')) {
if (!validBuildPath(platform.buildPath)) {
throw new Error('Build path must end in a trailing slash or you will get weird file names.')
}

Expand Down
3 changes: 2 additions & 1 deletion lib/cleanDirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

const cleanDir = require('./cleanDir');
const validBuildPath = require("./utils/validBuildPath");

/**
* Takes a platform config object and a properties
Expand All @@ -24,7 +25,7 @@ const cleanDir = require('./cleanDir');
* @returns {null}
*/
function cleanDirs(dictionary, platform) {
if (platform.buildPath && platform.buildPath.slice(-1) !== '/') {
if (!validBuildPath(platform.buildPath)) {
throw new Error('Build path must end in a trailing slash or you will get weird file names.')
}

Expand Down
3 changes: 2 additions & 1 deletion lib/cleanFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

const cleanFile = require('./cleanFile');
const validBuildPath = require("./utils/validBuildPath");

/**
* Takes a platform config object and a dictionary
Expand All @@ -24,7 +25,7 @@ const cleanFile = require('./cleanFile');
* @returns {null}
*/
function cleanFiles(dictionary, platform) {
if (platform.buildPath && platform.buildPath.slice(-1) !== '/') {
if (!validBuildPath(platform.buildPath)) {
throw new Error('Build path must end in a trailing slash or you will get weird file names.')
}

Expand Down
26 changes: 26 additions & 0 deletions lib/utils/validBuildPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

const path = require("path");

/**
* Check if the build path is valid.
*
* @param buildPath
* @returns {boolean}
*/
function validBuildPath(buildPath) {
return !buildPath || (buildPath.slice(-1) === path.sep);
}

module.exports = validBuildPath;