Skip to content

Commit

Permalink
fix: improve bin/dev.js check
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 26, 2023
1 parent c528a6c commit caafbca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
25 changes: 13 additions & 12 deletions utils/sf-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

const { dirname } = require('path');
const { existsSync } = require('fs');
const { dirname, join } = require('path');
const { cosmiconfigSync } = require('cosmiconfig');
const { isPlugin } = require('./project-type');

Expand Down Expand Up @@ -71,13 +72,20 @@ const PACKAGE_DEFAULTS = {
// Path to resolved config object.
const resolvedConfigs = {};

const resolveConfig = (path, options = {}) => {
const resolveConfig = (path) => {
if (path && resolvedConfigs[path]) {
return resolvedConfigs[path];
}
const explorerSync = cosmiconfigSync('sfdev');
const result = explorerSync.search(path);

const dev = options.jsBinScripts ? 'ts-node "./bin/dev.js"' : '"./bin/dev"';
const PLUGIN_DEFAULTS = {
if (!path && result) {
path = dirname(result.filepath);
}

const usesJsBinScripts = existsSync(join(path, 'bin', 'dev.js'));
const dev = usesJsBinScripts ? 'ts-node "./bin/dev.js"' : '"./bin/dev"';
const pluginDefaults = {
scripts: {
...PACKAGE_DEFAULTS.scripts,
// wireit scripts don't need an entry in pjson scripts.
Expand Down Expand Up @@ -118,14 +126,7 @@ const resolveConfig = (path, options = {}) => {
},
};

const explorerSync = cosmiconfigSync('sfdev');
const result = explorerSync.search(path);

if (!path && result) {
path = dirname(result.filepath);
}

const defaults = path && isPlugin(path) ? PLUGIN_DEFAULTS : PACKAGE_DEFAULTS;
const defaults = path && isPlugin(path) ? pluginDefaults : PACKAGE_DEFAULTS;

const configFromFile = (result && result.config) || {};

Expand Down
11 changes: 2 additions & 9 deletions utils/standardize-pjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,15 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

const { readFileSync, existsSync } = require('fs');
const { readFileSync } = require('fs');
const { join } = require('path');
const { resolveConfig } = require('./sf-config');
const { semverIsLessThan } = require('./semver');

const PackageJson = require('./package-json');

function usesJsBinScripts(packageRoot) {
return existsSync(join(packageRoot, 'bin', 'dev.js'));
}

module.exports = (packageRoot = require('./package-path')) => {
const options = {
jsBinScripts: usesJsBinScripts(packageRoot),
};
const config = resolveConfig(packageRoot, options);
const config = resolveConfig(packageRoot);
const pjson = new PackageJson(packageRoot);

const license = pjson.get('license');
Expand Down

0 comments on commit caafbca

Please sign in to comment.