Skip to content

Commit

Permalink
feat: build related package.json entries are overridden instead of re…
Browse files Browse the repository at this point in the history
…tained

This reduces boilerplate work post-inject in the standard case.
  • Loading branch information
snorrees committed Oct 31, 2022
1 parent c09c4f3 commit deb87b0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 334 deletions.
11 changes: 11 additions & 0 deletions docs/presets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Presets

## semver-workflow

Prompt for branch config

Prompt for releaserc config



## renovate
328 changes: 0 additions & 328 deletions src/actions/verify.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/actions/verify/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export function validateModule(packageJson: PackageJson): string[] {
`.trimStart()
)
}

if (packageJson.typings) {
errors.push(outdent`Found typings field in package.json. Use types instead.`)
}
return errors
}

Expand Down
15 changes: 9 additions & 6 deletions src/npm/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ export async function writePackageJson(data: PackageData, options: InjectOptions

const manifest: PackageJson = {
...alwaysOnTop,
// Use already configured values by default
...(prev || {}),
// but we override these to enforce standardization
source: flags.typescript ? './src/index.ts' : './src/index.js',
main: './lib/cjs/index.js',
module: './lib/esm/index.js',
Expand All @@ -252,14 +255,11 @@ export async function writePackageJson(data: PackageData, options: InjectOptions
},
},
files: ['src', 'lib', 'v2-incompatible.js', 'sanity.json'],
scripts: {},
repository: {},
engines: {
node: '>=14.0.0',
},

// Use already configured values by default
...(prev || {}),
scripts: {...prev.scripts},
repository: {...prev.repository},

// We're de-declaring properties because of key order in package.json
...alwaysOnTop,
Expand All @@ -272,6 +272,9 @@ export async function writePackageJson(data: PackageData, options: InjectOptions
...urlsFromOrigin(gitOrigin),
}

// we use types, not typings
delete manifest.typings

const differs = JSON.stringify(prev) !== JSON.stringify(manifest)
log.debug('Does manifest differ? %s', differs ? 'yes' : 'no')
if (differs) {
Expand Down Expand Up @@ -313,7 +316,7 @@ export function addScript(cmd: string, existing: string) {
return existing
}

return existing ? `${existing} && ${cmd}` : cmd
return cmd
}

export async function addPackageJsonScripts(
Expand Down

0 comments on commit deb87b0

Please sign in to comment.