Skip to content

Commit

Permalink
feat(js): create @nrwl/js package and move @nrwl/workspace:tsc to it (n…
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Nov 12, 2021
1 parent 18f2e70 commit d28f571
Show file tree
Hide file tree
Showing 47 changed files with 515 additions and 40 deletions.
1 change: 1 addition & 0 deletions .cz-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @nrwl/workspace:tsc
# @nrwl/js:tsc

Build a project using TypeScript.

Expand Down
1 change: 1 addition & 0 deletions docs/angular/executors.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"detox",
"gatsby",
"jest",
"js",
"linter",
"next",
"node",
Expand Down
1 change: 1 addition & 0 deletions docs/angular/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"express",
"gatsby",
"jest",
"js",
"linter",
"nest",
"next",
Expand Down
3 changes: 2 additions & 1 deletion docs/builders.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"node",
"storybook",
"web",
"workspace"
"workspace",
"js"
]
30 changes: 24 additions & 6 deletions docs/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
},
Expand Down Expand Up @@ -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"
}
]
},
Expand Down Expand Up @@ -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"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @nrwl/workspace:tsc
# @nrwl/js:tsc

Build a project using TypeScript.

Expand Down
1 change: 1 addition & 0 deletions docs/node/executors.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"detox",
"gatsby",
"jest",
"js",
"linter",
"next",
"node",
Expand Down
1 change: 1 addition & 0 deletions docs/node/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"express",
"gatsby",
"jest",
"js",
"linter",
"nest",
"next",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @nrwl/workspace:tsc
# @nrwl/js:tsc

Build a project using TypeScript.

Expand Down
1 change: 1 addition & 0 deletions docs/react/executors.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"detox",
"gatsby",
"jest",
"js",
"linter",
"next",
"node",
Expand Down
1 change: 1 addition & 0 deletions docs/react/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"express",
"gatsby",
"jest",
"js",
"linter",
"nest",
"next",
Expand Down
10 changes: 10 additions & 0 deletions e2e/js/jest.config.js
Original file line number Diff line number Diff line change
@@ -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: '<rootDir>/tsconfig.spec.json' } },
displayName: 'e2e-js',
};
34 changes: 34 additions & 0 deletions e2e/js/project.json
Original file line number Diff line number Diff line change
@@ -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"]
}
42 changes: 42 additions & 0 deletions e2e/js/src/js.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
13 changes: 13 additions & 0 deletions e2e/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": [],
"files": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}
16 changes: 16 additions & 0 deletions e2e/js/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
1 change: 1 addition & 0 deletions e2e/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
3 changes: 3 additions & 0 deletions packages/js/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]]
}
18 changes: 18 additions & 0 deletions packages/js/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions packages/js/README.md
Original file line number Diff line number Diff line change
@@ -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).
17 changes: 17 additions & 0 deletions packages/js/executors.json
Original file line number Diff line number Diff line change
@@ -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."
}
}
}
6 changes: 6 additions & 0 deletions packages/js/generators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/schema",
"name": "js",
"version": "0.0.1",
"generators": {}
}
10 changes: 10 additions & 0 deletions packages/js/jest.config.js
Original file line number Diff line number Diff line change
@@ -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: '<rootDir>/tsconfig.spec.json' } },
displayName: 'jest',
testEnvironment: 'node',
};
4 changes: 4 additions & 0 deletions packages/js/migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"generators": {},
"packageJsonUpdates": {}
}
12 changes: 12 additions & 0 deletions packages/js/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
11 changes: 11 additions & 0 deletions packages/js/package.json
Original file line number Diff line number Diff line change
@@ -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": "*"
}
}
Loading

0 comments on commit d28f571

Please sign in to comment.