From 4c2f98ebf94382bd76baf08e7ad90e6d7f9cc49f Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Thu, 27 Jul 2023 19:18:39 -0400 Subject: [PATCH] fix(js): generate correct standalone setup (#18355) --- packages/js/src/generators/library/library.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index 3a84b740f25a6..74f93f7f56f5f 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -238,7 +238,7 @@ export async function addLint( options: NormalizedSchema ): Promise { const { lintProjectGenerator } = ensurePackage('@nx/linter', nxVersion); - return lintProjectGenerator(tree, { + const task = lintProjectGenerator(tree, { project: options.name, linter: options.linter, skipFormat: true, @@ -252,6 +252,22 @@ export async function addLint( setParserOptionsProject: options.setParserOptionsProject, rootProject: options.rootProject, }); + // Also update the root .eslintrc.json lintProjectGenerator will not generate it for root projects. + // But we need to set the package.json checks. + if (options.rootProject) { + updateJson(tree, '.eslintrc.json', (json) => { + json.overrides ??= []; + json.overrides.push({ + files: ['*.json'], + parser: 'jsonc-eslint-parser', + rules: { + '@nx/dependency-checks': 'error', + }, + }); + return json; + }); + } + return task; } function addBundlerDependencies(tree: Tree, options: NormalizedSchema) { @@ -351,8 +367,8 @@ function createFiles(tree: Tree, options: NormalizedSchema, filesDir: string) { updateJson(tree, packageJsonPath, (json) => { json.name = options.importPath; json.version = '0.0.1'; - // If the package is publishable, we should remove the private field. - if (json.private && options.publishable) { + // If the package is publishable or root/standalone, we should remove the private field. + if (json.private && (options.publishable || options.rootProject)) { delete json.private; } return {