Skip to content

Commit

Permalink
feat: run pkg-utils in strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard committed Jan 2, 2023
1 parent 3e385cc commit 4ec8613
Show file tree
Hide file tree
Showing 9 changed files with 652 additions and 36 deletions.
622 changes: 622 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@
"assets"
],
"scripts": {
"prebuild": "npm run clean",
"build": "tsc",
"postbuild": "node executable-index.js",
"build": "run-s clean && tsc && node executable-index.js",
"clean": "rimraf lib",
"commit": "git-cz",
"compile": "tsc --noEmit",
"format": "prettier src -w",
"lint": "eslint .",
"prepare": "husky install",
"prepublishOnly": "npm run build",
"prepublishOnly": "run-s build",
"test": "tap",
"watch": "tsc --watch"
},
Expand Down Expand Up @@ -110,6 +108,7 @@
"husky": "^8.0.2",
"json5": "^2.2.1",
"lint-staged": "^13.0.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.3.0",
"readdirp": "^3.6.0",
Expand Down
10 changes: 4 additions & 6 deletions src/actions/verify/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {PackageJson, SanityStudioJson, SanityV2Json} from './types'
import {ParsedCommandLine} from 'typescript'

export const expectedScripts = {
prebuild: `plugin-kit verify-package --silent && pkg-utils`,
build: 'pkg-utils build',
watch: 'pkg-utils watch',
build:
'run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict',
watch: 'pkg-utils watch --strict',
'link-watch': 'plugin-kit link-watch',
prepublishOnly: 'npm run build',
prepublishOnly: 'run-s build',
}

const expectedModulesFields = ['source', 'exports', 'main', 'module', 'files']
Expand Down Expand Up @@ -115,8 +115,6 @@ export function validateScripts(packageJson: PackageJson): string[] {
.join(', ')}
This checks for that the commands-strings includes these terms.
For example, this will validate ok:
"prebuild": "npm run clean && ${expectedScripts.prebuild}",
Please add the following to your package.json "scripts":
Expand Down
3 changes: 1 addition & 2 deletions src/npm/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {PackageJson} from '../actions/verify/types'
import {forcedDevPackageVersions, forcedPackageVersions} from '../configs/forced-package-versions'
const defaultDependencies = [incompatiblePluginPackage]

const defaultDevDependencies = ['rimraf', 'react', 'sanity']
const defaultDevDependencies = ['npm-run-all', 'rimraf', 'react', 'sanity']
const defaultPeerDependencies = ['react', 'sanity']

const readFile = util.promisify(fs.readFile)
Expand Down Expand Up @@ -365,7 +365,6 @@ export async function addBuildScripts(manifest: PackageJson, options: InjectOpti
return false
}
return addPackageJsonScripts(manifest, options, (scripts) => {
scripts.prebuild = addScript('npm run clean && ' + expectedScripts.prebuild, scripts.prebuild)
scripts.build = addScript(expectedScripts.build, scripts.build)
scripts.clean = addScript(`rimraf lib`, scripts.clean)
scripts['link-watch'] = addScript(expectedScripts['link-watch'], scripts['link-watch'])
Expand Down
11 changes: 4 additions & 7 deletions tap-snapshots/test/verify-package.test.ts.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,16 @@ To skip this validation add the following to your package.json:
}
----------------------------------------------------------
[error]
The following script commands did not contain expected defaults: prebuild, build, watch, link-watch, prepublishOnly
The following script commands did not contain expected defaults: build, watch, link-watch, prepublishOnly
This checks for that the commands-strings includes these terms.
For example, this will validate ok:
"prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
Please add the following to your package.json "scripts":
"prebuild": "plugin-kit verify-package --silent && pkg-utils",
"build": "pkg-utils build",
"watch": "pkg-utils watch",
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
"watch": "pkg-utils watch --strict",
"link-watch": "plugin-kit link-watch",
"prepublishOnly": "npm run build"
"prepublishOnly": "run-s build"
To skip this validation add the following to your package.json:
"sanityPlugin": {
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/inject/valid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
"sanity.json"
],
"scripts": {
"prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
"build": "pkg-utils build --no-cache",
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
"clean": "rimraf lib",
"link-watch": "plugin-kit link-watch",
"lint": "eslint .",
"prepublishOnly": "npm run build",
"watch": "pkg-utils watch"
"prepublishOnly": "run-s build",
"watch": "pkg-utils watch --strict"
},
"dependencies": {
"@sanity/incompatible-plugin": "^0.0.1-studio-v3.1"
Expand All @@ -55,6 +54,7 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.30.0",
"eslint-plugin-react-hooks": "^4.5.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.6.2",
"prettier-plugin-packagejson": "^2.3.0",
"react": "^18.2.0",
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/verify-package/invalid-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
"sanity.json"
],
"scripts": {
"prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
"build": "pkg-utils build",
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
"clean": "rimraf lib",
"link-watch": "plugin-kit link-watch",
"lint": "eslint .",
"prepublishOnly": "npm run build",
"watch": "pkg-utils watch"
"prepublishOnly": "run-s build",
"watch": "pkg-utils watch --strict"
},
"dependencies": {
"@sanity/incompatible-plugin": "^0.0.1-studio-v3.1"
Expand All @@ -50,6 +49,7 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.30.0",
"eslint-plugin-react-hooks": "^4.5.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.6.2",
"prettier-plugin-packagejson": "^2.3.0",
"react": "^18.2.0",
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/verify-package/valid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
"sanity.json"
],
"scripts": {
"prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
"build": "pkg-utils build --no-cache",
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
"clean": "rimraf lib",
"link-watch": "plugin-kit link-watch",
"lint": "eslint .",
"prepublishOnly": "npm run build",
"watch": "pkg-utils watch"
"prepublishOnly": "run-s build",
"watch": "pkg-utils watch --strict"
},
"dependencies": {
"@sanity/incompatible-plugin": "^0.0.1-studio-v3.1"
Expand All @@ -51,6 +50,7 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.30.0",
"eslint-plugin-react-hooks": "^4.5.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.6.2",
"prettier-plugin-packagejson": "^2.3.0",
"react": "^18.2.0",
Expand Down
11 changes: 6 additions & 5 deletions test/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const defaultDevDependencies = [
'eslint-plugin-prettier',
'eslint-plugin-react',
'eslint-plugin-react-hooks',
'npm-run-all',
'prettier',
'prettier-plugin-packagejson',
'react',
Expand Down Expand Up @@ -98,11 +99,11 @@ tap.test('plugin-kit init --force in empty directory', async (t) => {
scripts: {
clean: 'rimraf lib',
lint: 'eslint .',
prebuild: 'npm run clean && plugin-kit verify-package --silent && pkg-utils',
build: 'pkg-utils build',
watch: 'pkg-utils watch',
build:
'run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict',
watch: 'pkg-utils watch --strict',
'link-watch': 'plugin-kit link-watch',
prepublishOnly: 'npm run build',
prepublishOnly: 'run-s build',
},
repository: {
type: 'git',
Expand Down Expand Up @@ -188,7 +189,7 @@ tap.test('plugin-kit init --force with all the opt-outs in empty directory', asy
)
t.strictSame(
Object.keys(pkg.devDependencies ?? {}),
['@sanity/pkg-utils', '@sanity/plugin-kit', 'react', 'rimraf', 'sanity'],
['@sanity/pkg-utils', '@sanity/plugin-kit', 'npm-run-all', 'react', 'rimraf', 'sanity'],
'should have expected devDependencies'
)
},
Expand Down

0 comments on commit 4ec8613

Please sign in to comment.