Skip to content

Commit 4ec8613

Browse files
feat: run pkg-utils in strict mode
1 parent 3e385cc commit 4ec8613

File tree

9 files changed

+652
-36
lines changed

9 files changed

+652
-36
lines changed

package-lock.json

Lines changed: 622 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@
3333
"assets"
3434
],
3535
"scripts": {
36-
"prebuild": "npm run clean",
37-
"build": "tsc",
38-
"postbuild": "node executable-index.js",
36+
"build": "run-s clean && tsc && node executable-index.js",
3937
"clean": "rimraf lib",
4038
"commit": "git-cz",
4139
"compile": "tsc --noEmit",
4240
"format": "prettier src -w",
4341
"lint": "eslint .",
4442
"prepare": "husky install",
45-
"prepublishOnly": "npm run build",
43+
"prepublishOnly": "run-s build",
4644
"test": "tap",
4745
"watch": "tsc --watch"
4846
},
@@ -110,6 +108,7 @@
110108
"husky": "^8.0.2",
111109
"json5": "^2.2.1",
112110
"lint-staged": "^13.0.3",
111+
"npm-run-all": "^4.1.5",
113112
"prettier": "^2.7.1",
114113
"prettier-plugin-packagejson": "^2.3.0",
115114
"readdirp": "^3.6.0",

src/actions/verify/validations.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import {PackageJson, SanityStudioJson, SanityV2Json} from './types'
1212
import {ParsedCommandLine} from 'typescript'
1313

1414
export const expectedScripts = {
15-
prebuild: `plugin-kit verify-package --silent && pkg-utils`,
16-
build: 'pkg-utils build',
17-
watch: 'pkg-utils watch',
15+
build:
16+
'run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict',
17+
watch: 'pkg-utils watch --strict',
1818
'link-watch': 'plugin-kit link-watch',
19-
prepublishOnly: 'npm run build',
19+
prepublishOnly: 'run-s build',
2020
}
2121

2222
const expectedModulesFields = ['source', 'exports', 'main', 'module', 'files']
@@ -115,8 +115,6 @@ export function validateScripts(packageJson: PackageJson): string[] {
115115
.join(', ')}
116116
117117
This checks for that the commands-strings includes these terms.
118-
For example, this will validate ok:
119-
"prebuild": "npm run clean && ${expectedScripts.prebuild}",
120118
121119
Please add the following to your package.json "scripts":
122120

src/npm/package.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {PackageJson} from '../actions/verify/types'
1616
import {forcedDevPackageVersions, forcedPackageVersions} from '../configs/forced-package-versions'
1717
const defaultDependencies = [incompatiblePluginPackage]
1818

19-
const defaultDevDependencies = ['rimraf', 'react', 'sanity']
19+
const defaultDevDependencies = ['npm-run-all', 'rimraf', 'react', 'sanity']
2020
const defaultPeerDependencies = ['react', 'sanity']
2121

2222
const readFile = util.promisify(fs.readFile)
@@ -365,7 +365,6 @@ export async function addBuildScripts(manifest: PackageJson, options: InjectOpti
365365
return false
366366
}
367367
return addPackageJsonScripts(manifest, options, (scripts) => {
368-
scripts.prebuild = addScript('npm run clean && ' + expectedScripts.prebuild, scripts.prebuild)
369368
scripts.build = addScript(expectedScripts.build, scripts.build)
370369
scripts.clean = addScript(`rimraf lib`, scripts.clean)
371370
scripts['link-watch'] = addScript(expectedScripts['link-watch'], scripts['link-watch'])

tap-snapshots/test/verify-package.test.ts.test.cjs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,16 @@ To skip this validation add the following to your package.json:
5252
}
5353
----------------------------------------------------------
5454
[error]
55-
The following script commands did not contain expected defaults: prebuild, build, watch, link-watch, prepublishOnly
55+
The following script commands did not contain expected defaults: build, watch, link-watch, prepublishOnly
5656
5757
This checks for that the commands-strings includes these terms.
58-
For example, this will validate ok:
59-
"prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
6058
6159
Please add the following to your package.json "scripts":
6260
63-
"prebuild": "plugin-kit verify-package --silent && pkg-utils",
64-
"build": "pkg-utils build",
65-
"watch": "pkg-utils watch",
61+
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
62+
"watch": "pkg-utils watch --strict",
6663
"link-watch": "plugin-kit link-watch",
67-
"prepublishOnly": "npm run build"
64+
"prepublishOnly": "run-s build"
6865
6966
To skip this validation add the following to your package.json:
7067
"sanityPlugin": {

test/fixtures/inject/valid/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@
3333
"sanity.json"
3434
],
3535
"scripts": {
36-
"prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
37-
"build": "pkg-utils build --no-cache",
36+
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
3837
"clean": "rimraf lib",
3938
"link-watch": "plugin-kit link-watch",
4039
"lint": "eslint .",
41-
"prepublishOnly": "npm run build",
42-
"watch": "pkg-utils watch"
40+
"prepublishOnly": "run-s build",
41+
"watch": "pkg-utils watch --strict"
4342
},
4443
"dependencies": {
4544
"@sanity/incompatible-plugin": "^0.0.1-studio-v3.1"
@@ -55,6 +54,7 @@
5554
"eslint-plugin-prettier": "^4.0.0",
5655
"eslint-plugin-react": "^7.30.0",
5756
"eslint-plugin-react-hooks": "^4.5.0",
57+
"npm-run-all": "^4.1.5",
5858
"prettier": "^2.6.2",
5959
"prettier-plugin-packagejson": "^2.3.0",
6060
"react": "^18.2.0",

test/fixtures/verify-package/invalid-eslint/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@
2929
"sanity.json"
3030
],
3131
"scripts": {
32-
"prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
33-
"build": "pkg-utils build",
32+
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
3433
"clean": "rimraf lib",
3534
"link-watch": "plugin-kit link-watch",
3635
"lint": "eslint .",
37-
"prepublishOnly": "npm run build",
38-
"watch": "pkg-utils watch"
36+
"prepublishOnly": "run-s build",
37+
"watch": "pkg-utils watch --strict"
3938
},
4039
"dependencies": {
4140
"@sanity/incompatible-plugin": "^0.0.1-studio-v3.1"
@@ -50,6 +49,7 @@
5049
"eslint-plugin-prettier": "^4.0.0",
5150
"eslint-plugin-react": "^7.30.0",
5251
"eslint-plugin-react-hooks": "^4.5.0",
52+
"npm-run-all": "^4.1.5",
5353
"prettier": "^2.6.2",
5454
"prettier-plugin-packagejson": "^2.3.0",
5555
"react": "^18.2.0",

test/fixtures/verify-package/valid/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@
2929
"sanity.json"
3030
],
3131
"scripts": {
32-
"prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
33-
"build": "pkg-utils build --no-cache",
32+
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
3433
"clean": "rimraf lib",
3534
"link-watch": "plugin-kit link-watch",
3635
"lint": "eslint .",
37-
"prepublishOnly": "npm run build",
38-
"watch": "pkg-utils watch"
36+
"prepublishOnly": "run-s build",
37+
"watch": "pkg-utils watch --strict"
3938
},
4039
"dependencies": {
4140
"@sanity/incompatible-plugin": "^0.0.1-studio-v3.1"
@@ -51,6 +50,7 @@
5150
"eslint-plugin-prettier": "^4.0.0",
5251
"eslint-plugin-react": "^7.30.0",
5352
"eslint-plugin-react-hooks": "^4.5.0",
53+
"npm-run-all": "^4.1.5",
5454
"prettier": "^2.6.2",
5555
"prettier-plugin-packagejson": "^2.3.0",
5656
"react": "^18.2.0",

test/init.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const defaultDevDependencies = [
2424
'eslint-plugin-prettier',
2525
'eslint-plugin-react',
2626
'eslint-plugin-react-hooks',
27+
'npm-run-all',
2728
'prettier',
2829
'prettier-plugin-packagejson',
2930
'react',
@@ -98,11 +99,11 @@ tap.test('plugin-kit init --force in empty directory', async (t) => {
9899
scripts: {
99100
clean: 'rimraf lib',
100101
lint: 'eslint .',
101-
prebuild: 'npm run clean && plugin-kit verify-package --silent && pkg-utils',
102-
build: 'pkg-utils build',
103-
watch: 'pkg-utils watch',
102+
build:
103+
'run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict',
104+
watch: 'pkg-utils watch --strict',
104105
'link-watch': 'plugin-kit link-watch',
105-
prepublishOnly: 'npm run build',
106+
prepublishOnly: 'run-s build',
106107
},
107108
repository: {
108109
type: 'git',
@@ -188,7 +189,7 @@ tap.test('plugin-kit init --force with all the opt-outs in empty directory', asy
188189
)
189190
t.strictSame(
190191
Object.keys(pkg.devDependencies ?? {}),
191-
['@sanity/pkg-utils', '@sanity/plugin-kit', 'react', 'rimraf', 'sanity'],
192+
['@sanity/pkg-utils', '@sanity/plugin-kit', 'npm-run-all', 'react', 'rimraf', 'sanity'],
192193
'should have expected devDependencies'
193194
)
194195
},

0 commit comments

Comments
 (0)