Skip to content

Commit

Permalink
fix!: pkg-utils validates if exports are missing (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored Apr 11, 2024
1 parent d3ee8a3 commit 3daaa3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
19 changes: 5 additions & 14 deletions src/actions/verify/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const expectedScripts = {
prepublishOnly: 'npm run build',
}

const expectedModulesFields = ['exports', 'main', 'files']
const expectedModulesFields = ['main', 'files']

function filesWithSuffixes(fileBases: string[], suffixes: string[]): string[] {
return fileBases.flatMap((file) => suffixes.map((suffix) => `${file}.${suffix}`))
Expand Down Expand Up @@ -48,23 +48,14 @@ export function validateModule(packageJson: PackageJson, options: {outDir: strin
if (missingFields.length) {
errors.push(
outdent`
Expected exports, main, files entries in package.json, but ${missingFields.join(
', ',
)} where missing.
Expected main, files entries in package.json, but ${missingFields.join(', ')} where missing.
Example:
Given a plugin with entry-point in src/index.ts, using default @sanity/pkg-utils build command,
package.json should contain the following entries to ensure that commonjs and esm outputs are built into ${outDir}:
Given a plugin with entry-point in src/index.ts, using a default @sanity/pkg-utils build command,
the package.json should contain the following entries to ensure that commonjs and esm outputs are built into ${outDir}:
"exports": {
".": {
"source": "./src/index.ts",
"import": "./${outDir}/index.mjs",
"default": "./${outDir}/index.js"
}
},
"main": "./${outDir}/index.js",
"main": "./${outDir}/index.ts",
"types": "./${outDir}/index.d.ts",
"files": [
"${outDir}",
Expand Down
15 changes: 4 additions & 11 deletions tap-snapshots/test/verify-package.test.ts.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,14 @@ To skip this validation add the following to your package.json:
}
----------------------------------------------------------
[error]
Expected exports, main, files entries in package.json, but exports, main where missing.
Expected main, files entries in package.json, but main where missing.
Example:
Given a plugin with entry-point in src/index.ts, using default @sanity/pkg-utils build command,
package.json should contain the following entries to ensure that commonjs and esm outputs are built into dist:
Given a plugin with entry-point in src/index.ts, using a default @sanity/pkg-utils build command,
the package.json should contain the following entries to ensure that commonjs and esm outputs are built into dist:
"exports": {
".": {
"source": "./src/index.ts",
"import": "./dist/index.mjs",
"default": "./dist/index.js"
}
},
"main": "./dist/index.js",
"main": "./dist/index.ts",
"types": "./dist/index.d.ts",
"files": [
"dist",
Expand Down

0 comments on commit 3daaa3d

Please sign in to comment.