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: allow dev.js in wireit scripts #232

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 43 additions & 42 deletions utils/sf-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,55 +68,56 @@ const PACKAGE_DEFAULTS = {
},
};

const PLUGIN_DEFAULTS = {
scripts: {
...PACKAGE_DEFAULTS.scripts,
// wireit scripts don't need an entry in pjson scripts.
// remove these from scripts and let wireit handle them (just repeat running yarn test)
// https://github.com/google/wireit/blob/main/CHANGELOG.md#094---2023-01-30
'test:command-reference': undefined,
'test:deprecation-policy': undefined,
'test:json-schema': undefined,
},
wireit: {
...PACKAGE_DEFAULTS.wireit,
'test:command-reference': {
command: `"./bin/dev" commandreference:generate --erroronwarnings`,
files: ['src/**/*.ts', 'messages/**', 'package.json'],
output: ['tmp/root'],
},
'test:deprecation-policy': {
command: '"./bin/dev" snapshot:compare',
files: ['src/**/*.ts'],
output: [],
dependencies: ['compile'],
},
'test:json-schema': {
command: '"./bin/dev" schema:compare',
files: ['src/**/*.ts', 'schemas'],
output: [],
},
test: {
dependencies: [
'test:compile',
'test:only',
'test:command-reference',
'test:deprecation-policy',
'lint',
'test:json-schema',
],
},
},
};

// Path to resolved config object.
const resolvedConfigs = {};

const resolveConfig = (path) => {
const resolveConfig = (path, options = {}) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: could add a jsBinScripts:string to options just for type niceness

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a .js file - so no types unfortunately

if (path && resolvedConfigs[path]) {
return resolvedConfigs[path];
}

const dev = options.jsBinScripts ? 'dev.js' : 'dev';
const PLUGIN_DEFAULTS = {
scripts: {
...PACKAGE_DEFAULTS.scripts,
// wireit scripts don't need an entry in pjson scripts.
// remove these from scripts and let wireit handle them (just repeat running yarn test)
// https://github.com/google/wireit/blob/main/CHANGELOG.md#094---2023-01-30
'test:command-reference': undefined,
'test:deprecation-policy': undefined,
'test:json-schema': undefined,
},
wireit: {
...PACKAGE_DEFAULTS.wireit,
'test:command-reference': {
command: `"./bin/${dev}" commandreference:generate --erroronwarnings`,
files: ['src/**/*.ts', 'messages/**', 'package.json'],
output: ['tmp/root'],
},
'test:deprecation-policy': {
command: `"./bin/${dev}" snapshot:compare`,
files: ['src/**/*.ts'],
output: [],
dependencies: ['compile'],
},
'test:json-schema': {
command: `"./bin/${dev}" schema:compare`,
files: ['src/**/*.ts', 'schemas'],
output: [],
},
test: {
dependencies: [
'test:compile',
'test:only',
'test:command-reference',
'test:deprecation-policy',
'lint',
'test:json-schema',
],
},
},
};

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

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

const { readFileSync } = require('fs');
const { readFileSync, existsSync } = 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 config = resolveConfig(packageRoot);
const options = {
jsBinScripts: usesJsBinScripts(packageRoot),
};
const config = resolveConfig(packageRoot, options);
const pjson = new PackageJson(packageRoot);

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