diff --git a/.cz-config.js b/.cz-config.js index 3d80efd241..1c658311d4 100644 --- a/.cz-config.js +++ b/.cz-config.js @@ -21,6 +21,7 @@ module.exports = { { name: 'gatsby', description: 'anything Gatsby specific' }, { name: 'nest', description: 'anything Nest specific' }, { name: 'node', description: 'anything Node specific' }, + { name: 'js', description: 'anything TS->JS specific' }, { name: 'express', description: 'anything Express specific' }, { name: 'nx-plugin', description: 'anything Nx Plugin specific' }, { name: 'react', description: 'anything React specific' }, diff --git a/docs/angular/api-workspace/executors/tsc.md b/docs/angular/api-js/executors/tsc.md similarity index 96% rename from docs/angular/api-workspace/executors/tsc.md rename to docs/angular/api-js/executors/tsc.md index 42034d661d..b0babee5f3 100644 --- a/docs/angular/api-workspace/executors/tsc.md +++ b/docs/angular/api-js/executors/tsc.md @@ -1,4 +1,4 @@ -# @nrwl/workspace:tsc +# @nrwl/js:tsc Build a project using TypeScript. diff --git a/docs/angular/executors.json b/docs/angular/executors.json index 20e4d08631..cb26dd84b8 100644 --- a/docs/angular/executors.json +++ b/docs/angular/executors.json @@ -4,6 +4,7 @@ "detox", "gatsby", "jest", + "js", "linter", "next", "node", diff --git a/docs/angular/generators.json b/docs/angular/generators.json index c2f47c1b32..4bc621d6ae 100644 --- a/docs/angular/generators.json +++ b/docs/angular/generators.json @@ -5,6 +5,7 @@ "express", "gatsby", "jest", + "js", "linter", "nest", "next", diff --git a/docs/builders.json b/docs/builders.json index d147d35dea..ee16974bd1 100644 --- a/docs/builders.json +++ b/docs/builders.json @@ -7,5 +7,6 @@ "node", "storybook", "web", - "workspace" + "workspace", + "js" ] diff --git a/docs/map.json b/docs/map.json index f273182d02..6efcf9da9e 100644 --- a/docs/map.json +++ b/docs/map.json @@ -352,11 +352,17 @@ "name": "run-script executor", "id": "run-script", "file": "angular/api-workspace/executors/run-script" - }, + } + ] + }, + { + "name": "js", + "id": "js", + "itemList": [ { "name": "tsc executor", "id": "tsc", - "file": "angular/api-workspace/executors/tsc" + "file": "angular/api-js/executors/tsc" } ] }, @@ -1660,11 +1666,17 @@ "name": "run-script executor", "id": "run-script", "file": "react/api-workspace/executors/run-script" - }, + } + ] + }, + { + "name": "js", + "id": "js", + "itemList": [ { "name": "tsc executor", "id": "tsc", - "file": "react/api-workspace/executors/tsc" + "file": "react/api-js/executors/tsc" } ] }, @@ -2932,11 +2944,17 @@ "name": "run-script executor", "id": "run-script", "file": "node/api-workspace/executors/run-script" - }, + } + ] + }, + { + "name": "js", + "id": "js", + "itemList": [ { "name": "tsc executor", "id": "tsc", - "file": "node/api-workspace/executors/tsc" + "file": "node/api-js/executors/tsc" } ] }, diff --git a/docs/node/api-workspace/executors/tsc.md b/docs/node/api-js/executors/tsc.md similarity index 96% rename from docs/node/api-workspace/executors/tsc.md rename to docs/node/api-js/executors/tsc.md index 04bbbfd7c6..0134023b65 100644 --- a/docs/node/api-workspace/executors/tsc.md +++ b/docs/node/api-js/executors/tsc.md @@ -1,4 +1,4 @@ -# @nrwl/workspace:tsc +# @nrwl/js:tsc Build a project using TypeScript. diff --git a/docs/node/executors.json b/docs/node/executors.json index 20e4d08631..cb26dd84b8 100644 --- a/docs/node/executors.json +++ b/docs/node/executors.json @@ -4,6 +4,7 @@ "detox", "gatsby", "jest", + "js", "linter", "next", "node", diff --git a/docs/node/generators.json b/docs/node/generators.json index c2f47c1b32..4bc621d6ae 100644 --- a/docs/node/generators.json +++ b/docs/node/generators.json @@ -5,6 +5,7 @@ "express", "gatsby", "jest", + "js", "linter", "nest", "next", diff --git a/docs/react/api-workspace/executors/tsc.md b/docs/react/api-js/executors/tsc.md similarity index 96% rename from docs/react/api-workspace/executors/tsc.md rename to docs/react/api-js/executors/tsc.md index 04bbbfd7c6..0134023b65 100644 --- a/docs/react/api-workspace/executors/tsc.md +++ b/docs/react/api-js/executors/tsc.md @@ -1,4 +1,4 @@ -# @nrwl/workspace:tsc +# @nrwl/js:tsc Build a project using TypeScript. diff --git a/docs/react/executors.json b/docs/react/executors.json index 20e4d08631..cb26dd84b8 100644 --- a/docs/react/executors.json +++ b/docs/react/executors.json @@ -4,6 +4,7 @@ "detox", "gatsby", "jest", + "js", "linter", "next", "node", diff --git a/docs/react/generators.json b/docs/react/generators.json index c2f47c1b32..4bc621d6ae 100644 --- a/docs/react/generators.json +++ b/docs/react/generators.json @@ -5,6 +5,7 @@ "express", "gatsby", "jest", + "js", "linter", "nest", "next", diff --git a/e2e/js/jest.config.js b/e2e/js/jest.config.js new file mode 100644 index 0000000000..d27c686d76 --- /dev/null +++ b/e2e/js/jest.config.js @@ -0,0 +1,10 @@ +module.exports = { + preset: '../../jest.preset.js', + transform: { + '^.+\\.[tj]sx?$': 'ts-jest', + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], + maxWorkers: 1, + globals: { 'ts-jest': { tsconfig: '/tsconfig.spec.json' } }, + displayName: 'e2e-js', +}; diff --git a/e2e/js/project.json b/e2e/js/project.json new file mode 100644 index 0000000000..8e60b21e5e --- /dev/null +++ b/e2e/js/project.json @@ -0,0 +1,34 @@ +{ + "root": "e2e/js", + "sourceRoot": "e2e/js", + "projectType": "application", + "targets": { + "e2e": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "commands": [ + { + "command": "yarn e2e-start-local-registry" + }, + { + "command": "yarn e2e-build-package-publish" + }, + { + "command": "nx run-e2e-tests e2e-jest" + } + ], + "parallel": false + } + }, + "run-e2e-tests": { + "executor": "@nrwl/jest:jest", + "options": { + "jestConfig": "e2e/js/jest.config.js", + "passWithNoTests": true, + "runInBand": true + }, + "outputs": ["coverage/e2e/js"] + } + }, + "implicitDependencies": ["jest"] +} diff --git a/e2e/js/src/js.spec.ts b/e2e/js/src/js.spec.ts new file mode 100644 index 0000000000..e936232d91 --- /dev/null +++ b/e2e/js/src/js.spec.ts @@ -0,0 +1,42 @@ +import { + checkFilesExist, + ensureNxProject, + readJson, + runNxCommandAsync, + uniq, +} from '@nrwl/nx-plugin/testing'; +describe('js e2e', () => { + it('should create js', async () => { + const plugin = uniq('js'); + ensureNxProject('@nrwl/js', 'dist//js'); + await runNxCommandAsync(`generate @nrwl/js:js ${plugin}`); + + const result = await runNxCommandAsync(`build ${plugin}`); + expect(result.stdout).toContain('Executor ran'); + }, 120000); + + describe('--directory', () => { + it('should create src in the specified directory', async () => { + const plugin = uniq('js'); + ensureNxProject('@nrwl/js', 'dist//js'); + await runNxCommandAsync( + `generate @nrwl/js:js ${plugin} --directory subdir` + ); + expect(() => + checkFilesExist(`libs/subdir/${plugin}/src/index.ts`) + ).not.toThrow(); + }, 120000); + }); + + describe('--tags', () => { + it('should add tags to the project', async () => { + const plugin = uniq('js'); + ensureNxProject('@nrwl/js', 'dist//js'); + await runNxCommandAsync( + `generate @nrwl/js:js ${plugin} --tags e2etag,e2ePackage` + ); + const project = readJson(`libs/${plugin}/project.json`); + expect(project.tags).toEqual(['e2etag', 'e2ePackage']); + }, 120000); + }); +}); diff --git a/e2e/js/tsconfig.json b/e2e/js/tsconfig.json new file mode 100644 index 0000000000..6d5abf8483 --- /dev/null +++ b/e2e/js/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "types": ["node", "jest"] + }, + "include": [], + "files": [], + "references": [ + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/e2e/js/tsconfig.spec.json b/e2e/js/tsconfig.spec.json new file mode 100644 index 0000000000..af4ac638d6 --- /dev/null +++ b/e2e/js/tsconfig.spec.json @@ -0,0 +1,16 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "**/*.test.ts", + "**/*.spec.ts", + "**/*.spec.tsx", + "**/*.spec.js", + "**/*.spec.jsx", + "**/*.d.ts" + ] +} diff --git a/e2e/utils/index.ts b/e2e/utils/index.ts index 7868b332b0..4f193a05ec 100644 --- a/e2e/utils/index.ts +++ b/e2e/utils/index.ts @@ -207,6 +207,7 @@ export function newProject({ name = uniq('proj') } = {}): string { `@nrwl/express`, `@nrwl/gatsby`, `@nrwl/jest`, + `@nrwl/js`, `@nrwl/linter`, `@nrwl/nest`, `@nrwl/next`, diff --git a/packages/js/.babelrc b/packages/js/.babelrc new file mode 100644 index 0000000000..cf7ddd99c6 --- /dev/null +++ b/packages/js/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]] +} diff --git a/packages/js/.eslintrc.json b/packages/js/.eslintrc.json new file mode 100644 index 0000000000..9d9c0db55b --- /dev/null +++ b/packages/js/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/packages/js/README.md b/packages/js/README.md new file mode 100644 index 0000000000..ddb5c8f8da --- /dev/null +++ b/packages/js/README.md @@ -0,0 +1,7 @@ +# js + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test js` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/packages/js/executors.json b/packages/js/executors.json new file mode 100644 index 0000000000..cf6562905d --- /dev/null +++ b/packages/js/executors.json @@ -0,0 +1,17 @@ +{ + "$schema": "http://json-schema.org/schema", + "executors": { + "tsc": { + "implementation": "./src/executors/tsc/tsc.impl", + "schema": "./src/executors/tsc/schema.json", + "description": "Build a project using TypeScript." + } + }, + "builders": { + "tsc": { + "implementation": "./src/executors/tsc/compat", + "schema": "./src/executors/tsc/schema.json", + "description": "Build a project using TypeScript." + } + } +} diff --git a/packages/js/generators.json b/packages/js/generators.json new file mode 100644 index 0000000000..030db21b58 --- /dev/null +++ b/packages/js/generators.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/schema", + "name": "js", + "version": "0.0.1", + "generators": {} +} diff --git a/packages/js/jest.config.js b/packages/js/jest.config.js new file mode 100644 index 0000000000..9eacdeb3e9 --- /dev/null +++ b/packages/js/jest.config.js @@ -0,0 +1,10 @@ +module.exports = { + preset: '../../jest.preset.js', + transform: { + '^.+\\.[tj]sx?$': 'ts-jest', + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], + globals: { 'ts-jest': { tsconfig: '/tsconfig.spec.json' } }, + displayName: 'jest', + testEnvironment: 'node', +}; diff --git a/packages/js/migrations.json b/packages/js/migrations.json new file mode 100644 index 0000000000..f9d34cef28 --- /dev/null +++ b/packages/js/migrations.json @@ -0,0 +1,4 @@ +{ + "generators": {}, + "packageJsonUpdates": {} +} diff --git a/packages/js/migrations.spec.ts b/packages/js/migrations.spec.ts new file mode 100644 index 0000000000..a3f53a6c04 --- /dev/null +++ b/packages/js/migrations.spec.ts @@ -0,0 +1,12 @@ +import path = require('path'); +import json = require('./migrations.json'); + +describe('JS migrations', () => { + it('should have valid paths', () => { + Object.values(json.generators).forEach((m: any) => { + expect(() => + require.resolve(path.join(__dirname, `${m.factory}.ts`)) + ).not.toThrow(); + }); + }); +}); diff --git a/packages/js/package.json b/packages/js/package.json new file mode 100644 index 0000000000..3f90dda468 --- /dev/null +++ b/packages/js/package.json @@ -0,0 +1,11 @@ +{ + "name": "@nrwl/js", + "version": "0.0.1", + "main": "src/index.js", + "generators": "./generators.json", + "executors": "./executors.json", + "dependencies": { + "@nrwl/workspace": "*", + "@nrwl/devkit": "*" + } +} diff --git a/packages/js/project.json b/packages/js/project.json new file mode 100644 index 0000000000..b4057d1d9f --- /dev/null +++ b/packages/js/project.json @@ -0,0 +1,70 @@ +{ + "root": "packages/js", + "sourceRoot": "packages/js/src", + "projectType": "library", + "targets": { + "lint": { + "executor": "@nrwl/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["packages/js/**/*.ts"] + } + }, + "test": { + "executor": "@nrwl/jest:jest", + "outputs": ["coverage/js"], + "options": { + "jestConfig": "packages/js/jest.config.js", + "passWithNoTests": true + } + }, + "build-base": { + "executor": "@nrwl/node:package", + "options": { + "outputPath": "build/packages/js", + "tsConfig": "packages/js/tsconfig.lib.json", + "packageJson": "packages/js/package.json", + "main": "packages/js/src/index.ts", + "updateBuildableProjectDepsInPackageJson": false, + "assets": [ + { + "input": "packages/js", + "glob": "**/files/**", + "output": "/" + }, + { + "input": "packages/js", + "glob": "**/files/**/.gitkeep", + "output": "/" + }, + { + "input": "packages/js", + "glob": "**/*.json", + "ignore": ["**/tsconfig*.json", "project.json"], + "output": "/" + }, + { + "input": "packages/js", + "glob": "**/*.js", + "output": "/" + }, + { + "input": "packages/js", + "glob": "**/*.d.ts", + "output": "/" + }, + "LICENSE" + ] + }, + "outputs": ["{options.outputPath}"] + }, + "build": { + "executor": "@nrwl/workspace:run-commands", + "outputs": ["build/packages/js"], + "options": { + "command": "node ./scripts/copy-readme.js js" + } + } + }, + "tags": [] +} diff --git a/packages/workspace/src/executors/tsc/compat.ts b/packages/js/src/executors/tsc/compat.ts similarity index 100% rename from packages/workspace/src/executors/tsc/compat.ts rename to packages/js/src/executors/tsc/compat.ts diff --git a/packages/workspace/src/executors/tsc/schema.d.ts b/packages/js/src/executors/tsc/schema.d.ts similarity index 100% rename from packages/workspace/src/executors/tsc/schema.d.ts rename to packages/js/src/executors/tsc/schema.d.ts diff --git a/packages/workspace/src/executors/tsc/schema.json b/packages/js/src/executors/tsc/schema.json similarity index 100% rename from packages/workspace/src/executors/tsc/schema.json rename to packages/js/src/executors/tsc/schema.json diff --git a/packages/workspace/src/executors/tsc/tsc.impl.spec.ts b/packages/js/src/executors/tsc/tsc.impl.spec.ts similarity index 89% rename from packages/workspace/src/executors/tsc/tsc.impl.spec.ts rename to packages/js/src/executors/tsc/tsc.impl.spec.ts index 6dd7acd14e..9faa570bc9 100644 --- a/packages/workspace/src/executors/tsc/tsc.impl.spec.ts +++ b/packages/js/src/executors/tsc/tsc.impl.spec.ts @@ -1,19 +1,19 @@ -jest.mock('../../core/project-graph'); -jest.mock('../../utilities/assets'); -jest.mock('../../utilities/buildable-libs-utils'); -jest.mock('../../utilities/fileutils'); -jest.mock('../../utilities/typescript/compilation'); +jest.mock('@nrwl/workspace/src/core/project-graph'); +jest.mock('@nrwl/workspace/src/utilities/assets'); +jest.mock('@nrwl/workspace/src/utilities/buildable-libs-utils'); +jest.mock('@nrwl/tao/src/utils/fileutils'); +jest.mock('@nrwl/workspace/src/utilities/typescript/compilation'); import { ExecutorContext } from '@nrwl/devkit'; import { join } from 'path'; -import { copyAssets } from '../../utilities/assets'; +import { copyAssets } from '@nrwl/workspace/src/utilities/assets'; import { calculateProjectDependencies, checkDependentProjectsHaveBeenBuilt, createTmpTsConfig, -} from '../../utilities/buildable-libs-utils'; -import { readJsonFile, writeJsonFile } from '../../utilities/fileutils'; -import { compileTypeScript } from '../../utilities/typescript/compilation'; +} from '@nrwl/workspace/src/utilities/buildable-libs-utils'; +import { readJsonFile, writeJsonFile } from '@nrwl/tao/src/utils/fileutils'; +import { compileTypeScript } from '@nrwl/workspace/src/utilities/typescript/compilation'; import { TypeScriptExecutorOptions } from './schema'; import { tscExecutor } from './tsc.impl'; diff --git a/packages/workspace/src/executors/tsc/tsc.impl.ts b/packages/js/src/executors/tsc/tsc.impl.ts similarity index 88% rename from packages/workspace/src/executors/tsc/tsc.impl.ts rename to packages/js/src/executors/tsc/tsc.impl.ts index f565be15c4..e01463a106 100644 --- a/packages/workspace/src/executors/tsc/tsc.impl.ts +++ b/packages/js/src/executors/tsc/tsc.impl.ts @@ -1,14 +1,19 @@ -import { ExecutorContext, normalizePath } from '@nrwl/devkit'; -import { basename, dirname, join, relative } from 'path'; -import { readCachedProjectGraph } from '../../core/project-graph'; -import { copyAssets } from '../../utilities/assets'; +import { + ExecutorContext, + normalizePath, + readJsonFile, + writeJsonFile, +} from '@nrwl/devkit'; +import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph'; +import { copyAssets } from '@nrwl/workspace/src/utilities/assets'; import { calculateProjectDependencies, checkDependentProjectsHaveBeenBuilt, createTmpTsConfig, -} from '../../utilities/buildable-libs-utils'; -import { readJsonFile, writeJsonFile } from '../../utilities/fileutils'; -import { compileTypeScript } from '../../utilities/typescript/compilation'; +} from '@nrwl/workspace/src/utilities/buildable-libs-utils'; +import { compileTypeScript } from '@nrwl/workspace/src/utilities/typescript/compilation'; +import { basename, dirname, join, relative } from 'path'; + import { TypeScriptExecutorOptions } from './schema'; export async function tscExecutor( diff --git a/packages/js/src/generators/.gitkeep b/packages/js/src/generators/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/js/src/index.ts b/packages/js/src/index.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/js/tsconfig.json b/packages/js/tsconfig.json new file mode 100644 index 0000000000..62ebbd9464 --- /dev/null +++ b/packages/js/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.base.json", + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/packages/js/tsconfig.lib.json b/packages/js/tsconfig.lib.json new file mode 100644 index 0000000000..037d796f28 --- /dev/null +++ b/packages/js/tsconfig.lib.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../../dist/out-tsc", + "declaration": true, + "types": ["node"] + }, + "exclude": ["**/*.spec.ts"], + "include": ["**/*.ts"] +} diff --git a/packages/js/tsconfig.spec.json b/packages/js/tsconfig.spec.json new file mode 100644 index 0000000000..36027728fe --- /dev/null +++ b/packages/js/tsconfig.spec.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "**/*.spec.ts", + "**/*.spec.tsx", + "**/*.spec.js", + "**/*.spec.jsx", + "**/*.d.ts" + ] +} diff --git a/packages/workspace/executors.json b/packages/workspace/executors.json index e2cf7dd4b8..9c32fca0ce 100644 --- a/packages/workspace/executors.json +++ b/packages/workspace/executors.json @@ -5,11 +5,6 @@ "schema": "./src/executors/run-commands/schema.json", "description": "Run any custom commands with Nx" }, - "tsc": { - "implementation": "./src/executors/tsc/compat", - "schema": "./src/executors/tsc/schema.json", - "description": "Build a project using TypeScript." - }, "run-script": { "implementation": "./src/executors/run-script/compat", "schema": "./src/executors/run-script/schema.json", @@ -22,11 +17,6 @@ "schema": "./src/executors/run-commands/schema.json", "description": "Run any custom commands with Nx" }, - "tsc": { - "implementation": "./src/executors/tsc/tsc.impl", - "schema": "./src/executors/tsc/schema.json", - "description": "Build a project using TypeScript." - }, "counter": { "implementation": "./src/executors/counter/counter.impl", "batchImplementation": "./src/executors/counter/counter.impl#batchCounter", diff --git a/packages/workspace/migrations.json b/packages/workspace/migrations.json index 6e2891d810..8aab6a2bdc 100644 --- a/packages/workspace/migrations.json +++ b/packages/workspace/migrations.json @@ -193,6 +193,12 @@ "description": "Set --parallel=1 for existing repos to preserve the existing behavior", "cli": "nx", "implementation": "./src/migrations/update-13-2-0/set-parallel-default" + }, + "13-3-0-tsc-location": { + "version": "13.3.0-beta.0", + "description": "@nrwl/workspace:tsc is now @nrwl/js:tsc", + "cli": "nx", + "implementation": "./src/migrations/update-13-3-0/update-tsc-executor-location" } }, "packageJsonUpdates": { diff --git a/packages/workspace/src/generators/library/library.spec.ts b/packages/workspace/src/generators/library/library.spec.ts index d7eba9faaf..d910275ce1 100644 --- a/packages/workspace/src/generators/library/library.spec.ts +++ b/packages/workspace/src/generators/library/library.spec.ts @@ -850,7 +850,7 @@ describe('lib', () => { expect(workspaceJson.projects['my-lib'].root).toEqual('libs/my-lib'); expect(workspaceJson.projects['my-lib'].architect.build).toBeTruthy(); expect(workspaceJson.projects['my-lib'].architect.build.builder).toBe( - '@nrwl/workspace:tsc' + '@nrwl/js:tsc' ); }); diff --git a/packages/workspace/src/generators/library/library.ts b/packages/workspace/src/generators/library/library.ts index 9d8f6cb09a..e7c1167c2b 100644 --- a/packages/workspace/src/generators/library/library.ts +++ b/packages/workspace/src/generators/library/library.ts @@ -12,9 +12,11 @@ import { GeneratorCallback, joinPathFragments, ProjectConfiguration, + addDependenciesToPackageJson, } from '@nrwl/devkit'; import { join } from 'path'; import { runTasksInSerial } from '../../utilities/run-tasks-in-serial'; +import { nxVersion } from '../../utils/versions'; import { Schema } from './schema'; // nx-ignore-next-line @@ -42,8 +44,9 @@ function addProject(tree: Tree, options: NormalizedSchema) { if (options.buildable) { const { libsDir } = getWorkspaceLayout(tree); + addDependenciesToPackageJson(tree, {}, { '@nrwl/js': nxVersion }); projectConfiguration.targets.build = { - executor: '@nrwl/workspace:tsc', + executor: '@nrwl/js:tsc', outputs: ['{options.outputPath}'], options: { outputPath: `dist/${libsDir}/${options.projectDirectory}`, diff --git a/packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.spec.ts b/packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.spec.ts new file mode 100644 index 0000000000..60a6b120da --- /dev/null +++ b/packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.spec.ts @@ -0,0 +1,85 @@ +import { + Tree, + writeJson, + readWorkspaceConfiguration, + addProjectConfiguration, + getProjects, + readJson, +} from '@nrwl/devkit'; +import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; +import { updateTscExecutorLocation } from './update-tsc-executor-location'; + +describe('add `defaultBase` in nx.json', () => { + let tree: Tree; + + beforeEach(async () => { + tree = createTreeWithEmptyWorkspace(2); + }); + + it('should update @nrwl/workspace:tsc -> @nrwl/js:tsc', async () => { + addProjectConfiguration(tree, 'tsc-project', { + root: 'projects/tsc-project', + targets: { + build: { + executor: '@nrwl/workspace:tsc', + }, + test: { + executor: '@nrwl/jest:jest', + }, + }, + }); + addProjectConfiguration(tree, 'other-project', { + root: 'projects/other-project', + targets: { + build: { + executor: '@nrwl/react:build', + }, + test: { + executor: '@nrwl/jest:jest', + }, + }, + }); + await updateTscExecutorLocation(tree); + const projects = Object.fromEntries(getProjects(tree).entries()); + expect(projects).toEqual({ + 'tsc-project': { + root: 'projects/tsc-project', + targets: { + build: { + executor: '@nrwl/js:tsc', + }, + test: { + executor: '@nrwl/jest:jest', + }, + }, + }, + 'other-project': { + root: 'projects/other-project', + targets: { + build: { + executor: '@nrwl/react:build', + }, + test: { + executor: '@nrwl/jest:jest', + }, + }, + }, + }); + }); + + it('should add @nrwl/js dependency', async () => { + addProjectConfiguration(tree, 'tsc-project', { + root: 'projects/tsc-project', + targets: { + build: { + executor: '@nrwl/workspace:tsc', + }, + }, + }); + await updateTscExecutorLocation(tree); + const packageJson = readJson(tree, 'package.json'); + expect(packageJson.devDependencies).toMatchObject({ + '@nrwl/js': expect.anything(), + }); + }); +}); diff --git a/packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.ts b/packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.ts new file mode 100644 index 0000000000..0a6daee3f9 --- /dev/null +++ b/packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.ts @@ -0,0 +1,42 @@ +import { + addDependenciesToPackageJson, + formatFiles, + GeneratorCallback, + getProjects, + installPackagesTask, + Tree, + updateProjectConfiguration, +} from '@nrwl/devkit'; +import { addDepsToPackageJson } from '@nrwl/workspace'; +import { nxVersion } from '../../utils/versions'; + +export async function updateTscExecutorLocation( + host: Tree +): Promise { + const projects = getProjects(host); + let used = false; + for (const [project, projectConfig] of projects.entries()) { + for (const [target, targetConfig] of Object.entries( + projectConfig.targets + )) { + if (targetConfig.executor === '@nrwl/workspace:tsc') { + projectConfig.targets[target].executor = '@nrwl/js:tsc'; + updateProjectConfiguration(host, project, projectConfig); + used = true; + } + } + } + if (used) { + addDependenciesToPackageJson( + host, + {}, + { + '@nrwl/js': nxVersion, + } + ); + } + await formatFiles(host); + return () => installPackagesTask(host); +} + +export default updateTscExecutorLocation; diff --git a/scripts/documentation/generate-generators-data.ts b/scripts/documentation/generate-generators-data.ts index c4eab9e42e..8df5530a61 100644 --- a/scripts/documentation/generate-generators-data.ts +++ b/scripts/documentation/generate-generators-data.ts @@ -35,9 +35,11 @@ function generateSchematicList( config: Configuration, flattener: SchemaFlattener ): Promise[] { - const schematicCollectionFile = path.join(config.root, 'generators.json'); + const schematicCollectionFilePath = path.join(config.root, 'generators.json'); + const schematicCollectionFile = readJsonSync(schematicCollectionFilePath); removeSync(config.schematicOutput); - const schematicCollection = readJsonSync(schematicCollectionFile).schematics; + const schematicCollection = + schematicCollectionFile.schematics || schematicCollectionFile.generators; return Object.keys(schematicCollection).map((schematicName) => { const schematic = { name: schematicName, diff --git a/tsconfig.base.json b/tsconfig.base.json index 2117d8b9c0..4637f80991 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -32,6 +32,7 @@ "@nrwl/gatsby": ["./packages/gatsby"], "@nrwl/jest": ["./packages/jest"], "@nrwl/jest/*": ["./packages/jest/*"], + "@nrwl/js": ["./packages/js/src"], "@nrwl/linter": ["./packages/linter"], "@nrwl/nest": ["./packages/nest"], "@nrwl/next": ["./packages/next"], diff --git a/workspace.json b/workspace.json index 71ce03f0e9..e81d195155 100644 --- a/workspace.json +++ b/workspace.json @@ -34,6 +34,8 @@ "express": "packages/express", "gatsby": "packages/gatsby", "jest": "packages/jest", + "js": "packages/js", + "e2e-js": "e2e/js", "linter": "packages/linter", "nest": "packages/nest", "next": "packages/next",