Skip to content

Commit

Permalink
feat(gcp-functions): allow keeping optional peerDeps and devDeps (#251)
Browse files Browse the repository at this point in the history
Fixes #250 

Adds an option called `omitOptionalDependencies`. This will control the
`isProduction` flag in `@nx/js`'s `createPackageJson` function.
  • Loading branch information
TriPSs authored Apr 11, 2024
2 parents 4a64d35 + 4faab1b commit 447e884
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/gcp-functions/src/executors/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { generatePackageJson } from '../../utils/generate-package-json'

export interface RawOptions extends WebpackExecutorOptions {
generateLockFile?: boolean
omitOptionalDependencies?: boolean
}

export async function buildExecutor(
Expand All @@ -34,6 +35,7 @@ export async function buildExecutor(
context,
options,
value.outfile,
rawOptions.omitOptionalDependencies,
rawOptions.generateLockFile
)
}
Expand Down
5 changes: 5 additions & 0 deletions packages/gcp-functions/src/executors/build/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
"default": false,
"x-deprecated": "The recommended method to detect circular dependencies in project code is to use a either a lint rule or other external tooling."
},
"omitOptionalDependencies": {
"type": "boolean",
"description": "If omitOptionalDependencies flag is set, it will remove devDependencies and optional peerDependencies",
"default": true
},
"maxWorkers": {
"type": "number",
"description": "Number of workers to use for type checking. (defaults to # of CPUS - 2)"
Expand Down
9 changes: 6 additions & 3 deletions packages/gcp-functions/src/utils/generate-package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export const generatePackageJson = (
context: ExecutorContext,
options: WebpackExecutorOptions,
outFile: string,
generateLockFile?: boolean
omitOptionalDependencies = true,
generateLockFile?: boolean,
) => {
const { root } = context.workspace.projects[context.projectName]

Expand All @@ -27,15 +28,17 @@ export const generatePackageJson = (
readCachedProjectGraph(),
{
root: context.root,
isProduction: true
isProduction: omitOptionalDependencies
}
)

if (!packageJson.main) {
packageJson.main = options.outputFileName || 'main.js'
}

delete packageJson.devDependencies
if (omitOptionalDependencies) {
delete packageJson.devDependencies
}

const dependencies = {}
const buildFile = fs.readFileSync(outFile, 'utf8')
Expand Down

0 comments on commit 447e884

Please sign in to comment.