feat(core): remove @nrwl/workspace:lib (#16122)
This commit is contained in:
parent
169b950fc6
commit
cafb49ac84
@ -6762,14 +6762,6 @@
|
||||
"isExternal": false,
|
||||
"disableCollapsible": false
|
||||
},
|
||||
{
|
||||
"id": "library",
|
||||
"path": "/packages/workspace/generators/library",
|
||||
"name": "library",
|
||||
"children": [],
|
||||
"isExternal": false,
|
||||
"disableCollapsible": false
|
||||
},
|
||||
{
|
||||
"id": "workspace-generator",
|
||||
"path": "/packages/workspace/generators/workspace-generator",
|
||||
|
||||
@ -3006,15 +3006,6 @@
|
||||
"path": "/packages/workspace/generators/new",
|
||||
"type": "generator"
|
||||
},
|
||||
"/packages/workspace/generators/library": {
|
||||
"description": "Create a library.",
|
||||
"file": "generated/packages/workspace/generators/library.json",
|
||||
"hidden": false,
|
||||
"name": "library",
|
||||
"originalFilePath": "/packages/workspace/src/generators/library/schema.json",
|
||||
"path": "/packages/workspace/generators/library",
|
||||
"type": "generator"
|
||||
},
|
||||
"/packages/workspace/generators/workspace-generator": {
|
||||
"description": "Generates a workspace generator.",
|
||||
"file": "generated/packages/workspace/generators/workspace-generator.json",
|
||||
|
||||
@ -2974,15 +2974,6 @@
|
||||
"path": "workspace/generators/new",
|
||||
"type": "generator"
|
||||
},
|
||||
{
|
||||
"description": "Create a library.",
|
||||
"file": "generated/packages/workspace/generators/library.json",
|
||||
"hidden": false,
|
||||
"name": "library",
|
||||
"originalFilePath": "/packages/workspace/src/generators/library/schema.json",
|
||||
"path": "workspace/generators/library",
|
||||
"type": "generator"
|
||||
},
|
||||
{
|
||||
"description": "Generates a workspace generator.",
|
||||
"file": "generated/packages/workspace/generators/workspace-generator.json",
|
||||
|
||||
@ -41,9 +41,8 @@ To create a generic TypeScript library (i.e. non-framework specific), use the [`
|
||||
```shell
|
||||
nx g @nrwl/js:lib my-new-lib
|
||||
|
||||
# If you want the library to be buildable or publishable to npm
|
||||
nx g @nrwl/web:lib my-new-lib --buildable
|
||||
nx g @nrwl/web:lib my-new-lib \
|
||||
# If you want the library to be publishable to npm
|
||||
nx g @nrwl/js:lib my-new-lib \
|
||||
--publishable \
|
||||
--importPath=@myorg/my-new-lib
|
||||
```
|
||||
|
||||
@ -34,7 +34,6 @@ This property is no longer needed because the Nx cli automatically will prompt y
|
||||
@nrwl/js:library
|
||||
@nrwl/next:library
|
||||
@nrwl/react:library
|
||||
@nrwl/workspace:library
|
||||
|
||||
None of the above
|
||||
```
|
||||
|
||||
@ -41,9 +41,8 @@ To create a generic TypeScript library (i.e. non-framework specific), use the [`
|
||||
```shell
|
||||
nx g @nrwl/js:lib my-new-lib
|
||||
|
||||
# If you want the library to be buildable or publishable to npm
|
||||
nx g @nrwl/web:lib my-new-lib --buildable
|
||||
nx g @nrwl/web:lib my-new-lib \
|
||||
# If you want the library to be publishable to npm
|
||||
nx g @nrwl/js:lib my-new-lib \
|
||||
--publishable \
|
||||
--importPath=@myorg/my-new-lib
|
||||
```
|
||||
|
||||
@ -7,7 +7,7 @@ Generators are useful individually, but reusing and composing generators allows
|
||||
Nx Devkit generators can be imported and invoked like any javascript function. They often return a `Promise`, so they can be used with the `await` keyword to mimic synchronous code. Because this is standard javascript, control flow logic can be adjusted with `if` blocks and `for` loops as usual.
|
||||
|
||||
```typescript
|
||||
import { libraryGenerator } from '@nrwl/workspace/generators';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
|
||||
export default async function (tree: Tree, schema: any) {
|
||||
await libraryGenerator(
|
||||
|
||||
@ -41,7 +41,7 @@ import {
|
||||
joinPathFragments,
|
||||
readProjectConfiguration,
|
||||
} from '@nrwl/devkit';
|
||||
import { libraryGenerator } from '@nrwl/workspace/generators';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
|
||||
export default async function (tree: Tree, schema: any) {
|
||||
await libraryGenerator(tree, { name: schema.name });
|
||||
|
||||
@ -15,7 +15,7 @@ Import the TypeScript schema into your generator file and replace the `any` in y
|
||||
|
||||
```typescript
|
||||
import { Tree, formatFiles, installPackagesTask } from '@nrwl/devkit';
|
||||
import { libraryGenerator } from '@nrwl/workspace/generators';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
|
||||
export default async function (tree: Tree, schema: GeneratorOptions) {
|
||||
await libraryGenerator(tree, { name: `${schema.name}-${schema.type || ''}` });
|
||||
|
||||
@ -51,7 +51,7 @@ The initial generator function creates a library.
|
||||
|
||||
```typescript
|
||||
import { Tree, formatFiles, installPackagesTask } from '@nrwl/devkit';
|
||||
import { libraryGenerator } from '@nrwl/workspace/generators';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
|
||||
export default async function (tree: Tree, schema: any) {
|
||||
await libraryGenerator(tree, { name: schema.name });
|
||||
|
||||
@ -4,12 +4,9 @@ import {
|
||||
runCLI,
|
||||
runCLIAsync,
|
||||
uniq,
|
||||
readJson,
|
||||
updateFile,
|
||||
expectJestTestsToPass,
|
||||
cleanupProject,
|
||||
readFile,
|
||||
checkFilesExist,
|
||||
} from '@nrwl/e2e/utils';
|
||||
|
||||
describe('Jest', () => {
|
||||
@ -20,7 +17,6 @@ describe('Jest', () => {
|
||||
afterAll(() => cleanupProject());
|
||||
|
||||
it('should be able test projects using jest', async () => {
|
||||
await expectJestTestsToPass('@nrwl/workspace:lib');
|
||||
await expectJestTestsToPass('@nrwl/js:lib');
|
||||
}, 500000);
|
||||
|
||||
@ -28,10 +24,8 @@ describe('Jest', () => {
|
||||
const testGlobal = `'My Test Global'`;
|
||||
const mylib = uniq('mylib');
|
||||
const utilLib = uniq('util-lib');
|
||||
runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`);
|
||||
runCLI(
|
||||
`generate @nrwl/workspace:lib ${utilLib} --importPath=@global-fun/globals`
|
||||
);
|
||||
runCLI(`generate @nrwl/js:lib ${mylib} --unit-test-runner jest`);
|
||||
runCLI(`generate @nrwl/js:lib ${utilLib} --importPath=@global-fun/globals`);
|
||||
updateFile(
|
||||
`libs/${utilLib}/src/index.ts`,
|
||||
stripIndents`
|
||||
@ -102,13 +96,13 @@ describe('Jest', () => {
|
||||
|
||||
it('should set the NODE_ENV to `test`', async () => {
|
||||
const mylib = uniq('mylib');
|
||||
runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`);
|
||||
runCLI(`generate @nrwl/js:lib ${mylib} --unit-test-runner jest`);
|
||||
|
||||
updateFile(
|
||||
`libs/${mylib}/src/lib/${mylib}.spec.ts`,
|
||||
`
|
||||
test('can access jest global', () => {
|
||||
expect(process.env.NODE_ENV).toBe('test');
|
||||
expect(process.env['NODE_ENV']).toBe('test');
|
||||
});
|
||||
`
|
||||
);
|
||||
@ -120,7 +114,7 @@ describe('Jest', () => {
|
||||
|
||||
it('should support multiple `coverageReporters` through CLI', async () => {
|
||||
const mylib = uniq('mylib');
|
||||
runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`);
|
||||
runCLI(`generate @nrwl/js:lib ${mylib} --unit-test-runner jest`);
|
||||
|
||||
updateFile(
|
||||
`libs/${mylib}/src/lib/${mylib}.spec.ts`,
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import {
|
||||
checkFilesDoNotExist,
|
||||
checkFilesExist,
|
||||
cleanupProject,
|
||||
createFile,
|
||||
expectJestTestsToPass,
|
||||
newProject,
|
||||
readJson,
|
||||
runCLI,
|
||||
runCLIAsync,
|
||||
uniq,
|
||||
updateFile,
|
||||
updateJson,
|
||||
@ -87,7 +89,72 @@ export function ${lib}Wildcard() {
|
||||
);
|
||||
}, 240_000);
|
||||
|
||||
it('should run default jest tests', async () => {
|
||||
await expectJestTestsToPass('@nrwl/js:lib');
|
||||
}, 240_000);
|
||||
it('should create a library that can be linted and tested', async () => {
|
||||
const libName = uniq('mylib');
|
||||
const dirName = uniq('dir');
|
||||
|
||||
runCLI(`generate @nrwl/js:lib ${libName} --directory ${dirName}`);
|
||||
|
||||
checkFilesExist(
|
||||
`libs/${dirName}/${libName}/src/index.ts`,
|
||||
`libs/${dirName}/${libName}/README.md`
|
||||
);
|
||||
|
||||
// Lint
|
||||
const result = runCLI(`lint ${dirName}-${libName}`);
|
||||
|
||||
expect(result).toContain(`Linting "${dirName}-${libName}"...`);
|
||||
expect(result).toContain('All files pass linting.');
|
||||
|
||||
// Test
|
||||
const testResult = await runCLIAsync(`test ${dirName}-${libName}`);
|
||||
expect(testResult.combinedOutput).toContain(
|
||||
'Test Suites: 1 passed, 1 total'
|
||||
);
|
||||
}, 500_000);
|
||||
|
||||
it('should be able to use and be used by other libs', () => {
|
||||
const consumerLib = uniq('consumer');
|
||||
const producerLib = uniq('producer');
|
||||
|
||||
runCLI(`generate @nrwl/js:lib ${consumerLib} --bundler=none`);
|
||||
runCLI(`generate @nrwl/js:lib ${producerLib} --bundler=none`);
|
||||
|
||||
updateFile(
|
||||
`libs/${producerLib}/src/lib/${producerLib}.ts`,
|
||||
'export const a = 0;'
|
||||
);
|
||||
|
||||
updateFile(
|
||||
`libs/${consumerLib}/src/lib/${consumerLib}.ts`,
|
||||
`
|
||||
import { a } from '@${scope}/${producerLib}';
|
||||
|
||||
export function ${consumerLib}() {
|
||||
return a + 1;
|
||||
}`
|
||||
);
|
||||
updateFile(
|
||||
`libs/${consumerLib}/src/lib/${consumerLib}.spec.ts`,
|
||||
`
|
||||
import { ${consumerLib} } from './${consumerLib}';
|
||||
|
||||
describe('', () => {
|
||||
it('should return 1', () => {
|
||||
expect(${consumerLib}()).toEqual(1);
|
||||
});
|
||||
});`
|
||||
);
|
||||
|
||||
runCLI(`test ${consumerLib}`);
|
||||
});
|
||||
|
||||
it('should not be able to be built when it has no bundler', () => {
|
||||
const nonBuildable = uniq('buildable');
|
||||
runCLI(`generate @nrwl/js:lib ${nonBuildable} --bundler=none`);
|
||||
|
||||
expect(() => runCLI(`build ${nonBuildable}`)).toThrow();
|
||||
|
||||
checkFilesDoNotExist(`dist/libs/${nonBuildable}/README.md`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -29,7 +29,7 @@ describe('Linter', () => {
|
||||
beforeAll(() => {
|
||||
projScope = newProject();
|
||||
runCLI(`generate @nrwl/react:app ${myapp} --tags=validtag`);
|
||||
runCLI(`generate @nrwl/workspace:lib ${mylib}`);
|
||||
runCLI(`generate @nrwl/js:lib ${mylib}`);
|
||||
});
|
||||
afterAll(() => cleanupProject());
|
||||
|
||||
@ -194,10 +194,8 @@ describe('Linter', () => {
|
||||
|
||||
runCLI(`generate @nrwl/react:app ${myapp2}`);
|
||||
runCLI(`generate @nrwl/react:lib ${lazylib}`);
|
||||
runCLI(
|
||||
`generate @nrwl/workspace:lib ${invalidtaglib} --tags=invalidtag`
|
||||
);
|
||||
runCLI(`generate @nrwl/workspace:lib ${validtaglib} --tags=validtag`);
|
||||
runCLI(`generate @nrwl/js:lib ${invalidtaglib} --tags=invalidtag`);
|
||||
runCLI(`generate @nrwl/js:lib ${validtaglib} --tags=validtag`);
|
||||
|
||||
const eslint = readJson('.eslintrc.json');
|
||||
eslint.overrides[0].rules[
|
||||
@ -255,9 +253,9 @@ describe('Linter', () => {
|
||||
const libC = uniq('tslib-c');
|
||||
|
||||
beforeAll(() => {
|
||||
runCLI(`generate @nrwl/workspace:lib ${libA}`);
|
||||
runCLI(`generate @nrwl/workspace:lib ${libB}`);
|
||||
runCLI(`generate @nrwl/workspace:lib ${libC}`);
|
||||
runCLI(`generate @nrwl/js:lib ${libA}`);
|
||||
runCLI(`generate @nrwl/js:lib ${libB}`);
|
||||
runCLI(`generate @nrwl/js:lib ${libC}`);
|
||||
|
||||
/**
|
||||
* create tslib-a structure
|
||||
@ -506,7 +504,7 @@ describe('Linter', () => {
|
||||
expect(appEslint.overrides[1].extends).toBeDefined();
|
||||
expect(e2eEslint.overrides[0].extends).toBeDefined();
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${mylib} --unitTestRunner=jest`);
|
||||
runCLI(`generate @nrwl/js:lib ${mylib} --unitTestRunner=jest`);
|
||||
verifySuccessfulMigratedSetup(myapp, mylib);
|
||||
|
||||
appEslint = readJson(`.eslintrc.json`);
|
||||
@ -535,7 +533,7 @@ describe('Linter', () => {
|
||||
expect(appEslint.overrides[1].extends).toBeDefined();
|
||||
expect(e2eEslint.overrides[0].extends).toBeDefined();
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${mylib} --no-interactive`);
|
||||
runCLI(`generate @nrwl/js:lib ${mylib} --no-interactive`);
|
||||
verifySuccessfulMigratedSetup(myapp, mylib);
|
||||
|
||||
appEslint = readJson(`.eslintrc.json`);
|
||||
@ -566,7 +564,7 @@ describe('Linter', () => {
|
||||
expect(appEslint.overrides[1].extends).toBeDefined();
|
||||
expect(e2eEslint.overrides[0].extends).toBeDefined();
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${mylib} --no-interactive`);
|
||||
runCLI(`generate @nrwl/js:lib ${mylib} --no-interactive`);
|
||||
verifySuccessfulMigratedSetup(myapp, mylib);
|
||||
|
||||
appEslint = readJson(`.eslintrc.json`);
|
||||
|
||||
@ -14,7 +14,7 @@ describe('project graph creation', () => {
|
||||
|
||||
it('should correctly build the nxdeps.json containing files for the project', () => {
|
||||
const libName = uniq('mylib');
|
||||
runCLI(`generate @nrwl/workspace:lib ${libName}`);
|
||||
runCLI(`generate @nrwl/js:lib ${libName}`);
|
||||
|
||||
runCLI(`graph --file=graph.json`);
|
||||
const { graph: graphJson } = readJson('graph.json');
|
||||
@ -25,7 +25,7 @@ describe('project graph creation', () => {
|
||||
it("should correctly build the nxdeps.json containing files for the project when root is ''", () => {
|
||||
const libName = uniq('mylib');
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${libName}`);
|
||||
runCLI(`generate @nrwl/js:lib ${libName}`);
|
||||
updateJson(`libs/${libName}/project.json`, (json) => ({
|
||||
...json,
|
||||
root: '',
|
||||
@ -41,8 +41,8 @@ describe('project graph creation', () => {
|
||||
const libName = uniq('mylib');
|
||||
const secondLibName = uniq('mysecondlib');
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${libName}`);
|
||||
runCLI(`generate @nrwl/workspace:lib ${secondLibName}`);
|
||||
runCLI(`generate @nrwl/js:lib ${libName}`);
|
||||
runCLI(`generate @nrwl/js:lib ${secondLibName}`);
|
||||
updateJson(`libs/${libName}/project.json`, (json) => ({
|
||||
...json,
|
||||
root: '',
|
||||
|
||||
@ -99,7 +99,7 @@ describe('Extra Nx Misc Tests', () => {
|
||||
describe('Run Commands', () => {
|
||||
const mylib = uniq('lib');
|
||||
beforeAll(() => {
|
||||
runCLI(`generate @nrwl/workspace:lib ${mylib}`);
|
||||
runCLI(`generate @nrwl/js:lib ${mylib}`);
|
||||
});
|
||||
|
||||
it('should not override environment variables already set when setting a custom env file path', async () => {
|
||||
@ -229,7 +229,7 @@ describe('Extra Nx Misc Tests', () => {
|
||||
|
||||
const folder = `dist/libs/${mylib}/some-folder`;
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${mylib}`);
|
||||
runCLI(`generate @nrwl/js:lib ${mylib}`);
|
||||
|
||||
runCLI(
|
||||
`generate @nrwl/workspace:run-commands build --command=echo --outputs=${folder}/ --project=${mylib}`
|
||||
|
||||
@ -17,9 +17,9 @@ describe('Nx Commands', () => {
|
||||
let proj3 = uniq('proj3');
|
||||
beforeAll(() => {
|
||||
newProject({ packageManager: 'npm' });
|
||||
runCLI(`generate @nrwl/workspace:lib ${proj1}`);
|
||||
runCLI(`generate @nrwl/workspace:lib ${proj2}`);
|
||||
runCLI(`generate @nrwl/workspace:lib ${proj3}`);
|
||||
runCLI(`generate @nrwl/js:lib ${proj1}`);
|
||||
runCLI(`generate @nrwl/js:lib ${proj2}`);
|
||||
runCLI(`generate @nrwl/js:lib ${proj3}`);
|
||||
});
|
||||
|
||||
afterAll(() => cleanupProject());
|
||||
|
||||
@ -6,7 +6,6 @@ import {
|
||||
runCLI,
|
||||
uniq,
|
||||
updateFile,
|
||||
expectJestTestsToPass,
|
||||
readFile,
|
||||
exists,
|
||||
updateProjectConfig,
|
||||
@ -16,6 +15,7 @@ import {
|
||||
getPackageManagerCommand,
|
||||
getSelectedPackageManager,
|
||||
runCommand,
|
||||
runCreateWorkspace,
|
||||
} from '@nrwl/e2e/utils';
|
||||
|
||||
let proj: string;
|
||||
@ -27,86 +27,6 @@ describe('Workspace Tests', () => {
|
||||
|
||||
afterAll(() => cleanupProject());
|
||||
|
||||
describe('@nrwl/workspace:library', () => {
|
||||
it('should create a library that can be tested and linted', async () => {
|
||||
const libName = uniq('mylib');
|
||||
const dirName = uniq('dir');
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${libName} --directory ${dirName}`);
|
||||
|
||||
checkFilesExist(
|
||||
`libs/${dirName}/${libName}/src/index.ts`,
|
||||
`libs/${dirName}/${libName}/README.md`
|
||||
);
|
||||
|
||||
// Lint
|
||||
const result = runCLI(`lint ${dirName}-${libName}`);
|
||||
|
||||
expect(result).toContain(`Linting "${dirName}-${libName}"...`);
|
||||
expect(result).toContain('All files pass linting.');
|
||||
|
||||
// Test
|
||||
await expectJestTestsToPass('@nrwl/workspace:lib');
|
||||
}, 100000);
|
||||
|
||||
it('should be able to use and be used by other libs', () => {
|
||||
const consumerLib = uniq('consumer');
|
||||
const producerLib = uniq('producer');
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${consumerLib}`);
|
||||
runCLI(`generate @nrwl/workspace:lib ${producerLib}`);
|
||||
|
||||
updateFile(
|
||||
`libs/${producerLib}/src/lib/${producerLib}.ts`,
|
||||
'export const a = 0;'
|
||||
);
|
||||
|
||||
updateFile(
|
||||
`libs/${consumerLib}/src/lib/${consumerLib}.ts`,
|
||||
`
|
||||
import { a } from '@${proj}/${producerLib}';
|
||||
|
||||
export function ${consumerLib}() {
|
||||
return a + 1;
|
||||
}`
|
||||
);
|
||||
updateFile(
|
||||
`libs/${consumerLib}/src/lib/${consumerLib}.spec.ts`,
|
||||
`
|
||||
import { ${consumerLib} } from './${consumerLib}';
|
||||
|
||||
describe('', () => {
|
||||
it('should return 1', () => {
|
||||
expect(${consumerLib}()).toEqual(1);
|
||||
});
|
||||
});`
|
||||
);
|
||||
|
||||
runCLI(`test ${consumerLib}`);
|
||||
});
|
||||
|
||||
it('should be able to be built when it is buildable', () => {
|
||||
const buildableLib = uniq('buildable');
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${buildableLib} --buildable`);
|
||||
|
||||
const result = runCLI(`build ${buildableLib}`);
|
||||
|
||||
expect(result).toContain(
|
||||
`Compiling TypeScript files for project "${buildableLib}"...`
|
||||
);
|
||||
expect(result).toContain(
|
||||
`Done compiling TypeScript files for project "${buildableLib}".`
|
||||
);
|
||||
|
||||
checkFilesExist(`dist/libs/${buildableLib}/README.md`);
|
||||
|
||||
const json = readJson(`dist/libs/${buildableLib}/package.json`);
|
||||
expect(json.main).toEqual('./src/index.js');
|
||||
expect(json.types).toEqual('./src/index.d.ts');
|
||||
});
|
||||
});
|
||||
|
||||
describe('@nrwl/workspace:npm-package', () => {
|
||||
it('should create a minimal npm package', () => {
|
||||
const npmPackage = uniq('npm-package');
|
||||
@ -130,178 +50,6 @@ describe('Workspace Tests', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('workspace-generator', () => {
|
||||
let custom: string;
|
||||
let failing: string;
|
||||
|
||||
beforeEach(() => {
|
||||
custom = uniq('custom');
|
||||
failing = uniq('custom-failing');
|
||||
runCLI(
|
||||
`g @nrwl/workspace:workspace-generator ${custom} --no-interactive`
|
||||
);
|
||||
runCLI(
|
||||
`g @nrwl/workspace:workspace-generator ${failing} --no-interactive`
|
||||
);
|
||||
|
||||
checkFilesExist(
|
||||
`tools/generators/${custom}/index.ts`,
|
||||
`tools/generators/${custom}/schema.json`
|
||||
);
|
||||
checkFilesExist(
|
||||
`tools/generators/${failing}/index.ts`,
|
||||
`tools/generators/${failing}/schema.json`
|
||||
);
|
||||
});
|
||||
|
||||
it('should compile only generator files with dependencies', () => {
|
||||
const workspace = uniq('workspace');
|
||||
|
||||
updateFile(
|
||||
'tools/utils/command-line-utils.ts',
|
||||
`
|
||||
export const noop = () => {}
|
||||
`
|
||||
);
|
||||
updateFile(
|
||||
'tools/utils/logger.ts',
|
||||
`
|
||||
export const log = (...args: any[]) => console.log(...args)
|
||||
`
|
||||
);
|
||||
updateFile(
|
||||
`tools/generators/utils.ts`,
|
||||
`
|
||||
export const noop = ()=>{}
|
||||
`
|
||||
);
|
||||
updateFile(`tools/generators/${custom}/index.ts`, (content) => {
|
||||
return `
|
||||
import { log } from '../../utils/logger'; \n
|
||||
${content}
|
||||
`;
|
||||
});
|
||||
|
||||
runCLI(`workspace-generator ${custom} ${workspace} --no-interactive -d`);
|
||||
|
||||
expect(() =>
|
||||
checkFilesExist(
|
||||
`dist/out-tsc/tools/generators/${custom}/index.js`,
|
||||
`dist/out-tsc/tools/generators/utils.js`,
|
||||
`dist/out-tsc/tools/utils/logger.js`
|
||||
)
|
||||
).not.toThrow();
|
||||
expect(() =>
|
||||
checkFilesExist(`dist/out-tsc/tools/utils/utils.js`)
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it('should support workspace-specific generators', async () => {
|
||||
const json = readJson(`tools/generators/${custom}/schema.json`);
|
||||
json.properties['directory'] = {
|
||||
type: 'string',
|
||||
description: 'lib directory',
|
||||
};
|
||||
json.properties['skipTsConfig'] = {
|
||||
type: 'boolean',
|
||||
description: 'skip changes to tsconfig',
|
||||
};
|
||||
json.properties['inlineprop'] = json.properties['name'];
|
||||
json.required = ['inlineprop'];
|
||||
delete json.properties['name'];
|
||||
|
||||
updateFile(
|
||||
`tools/generators/${custom}/schema.json`,
|
||||
JSON.stringify(json)
|
||||
);
|
||||
|
||||
const indexFile = readFile(`tools/generators/${custom}/index.ts`);
|
||||
updateFile(
|
||||
`tools/generators/${custom}/index.ts`,
|
||||
indexFile.replace(
|
||||
'name: schema.name',
|
||||
'name: schema.inlineprop, directory: schema.directory, skipTsConfig: schema.skipTsConfig'
|
||||
)
|
||||
);
|
||||
|
||||
const helpOutput = runCLI(`workspace-generator ${custom} --help`);
|
||||
expect(helpOutput).toContain(
|
||||
`workspace-generator ${custom} [inlineprop] (options)`
|
||||
);
|
||||
expect(helpOutput).toContain(`--directory`);
|
||||
expect(helpOutput).toContain(`--skipTsConfig`);
|
||||
|
||||
const workspace = uniq('workspace');
|
||||
const dryRunOutput = runCLI(
|
||||
`workspace-generator ${custom} ${workspace} --no-interactive --directory=dir --skipTsConfig=true -d`
|
||||
);
|
||||
expect(exists(`libs/dir/${workspace}/src/index.ts`)).toEqual(false);
|
||||
expect(dryRunOutput).toContain(
|
||||
`CREATE libs/dir/${workspace}/src/index.ts`
|
||||
);
|
||||
|
||||
runCLI(
|
||||
`workspace-generator ${custom} ${workspace} --no-interactive --directory=dir`
|
||||
);
|
||||
checkFilesExist(`libs/dir/${workspace}/src/index.ts`);
|
||||
|
||||
const jsonFailing = readJson(`tools/generators/${failing}/schema.json`);
|
||||
jsonFailing.properties = {};
|
||||
jsonFailing.required = [];
|
||||
updateFile(
|
||||
`tools/generators/${failing}/schema.json`,
|
||||
JSON.stringify(jsonFailing)
|
||||
);
|
||||
|
||||
updateFile(
|
||||
`tools/generators/${failing}/index.ts`,
|
||||
`
|
||||
export default function() {
|
||||
throw new Error();
|
||||
}
|
||||
`
|
||||
);
|
||||
|
||||
try {
|
||||
await runCLI(`workspace-generator ${failing} --no-interactive`);
|
||||
fail(`Should exit 1 for a workspace-generator that throws an error`);
|
||||
} catch (e) {}
|
||||
|
||||
const listOutput = runCLI('workspace-generator --list-generators');
|
||||
expect(listOutput).toContain(custom);
|
||||
expect(listOutput).toContain(failing);
|
||||
}, 1000000);
|
||||
|
||||
it('should support angular devkit schematics', () => {
|
||||
const angularDevkitSchematic = uniq('angular-devkit-schematic');
|
||||
runCLI(
|
||||
`g @nrwl/workspace:workspace-generator ${angularDevkitSchematic} --no-interactive`
|
||||
);
|
||||
|
||||
const json = readJson(
|
||||
`tools/generators/${angularDevkitSchematic}/schema.json`
|
||||
);
|
||||
json.properties = {};
|
||||
json.required = [];
|
||||
delete json.cli;
|
||||
updateFile(
|
||||
`tools/generators/${angularDevkitSchematic}/schema.json`,
|
||||
JSON.stringify(json)
|
||||
);
|
||||
|
||||
updateFile(
|
||||
`tools/generators/${angularDevkitSchematic}/index.ts`,
|
||||
`
|
||||
export default function() {
|
||||
return (tree) => tree;
|
||||
}
|
||||
`
|
||||
);
|
||||
|
||||
runCLI(`workspace-generator ${angularDevkitSchematic} --no-interactive`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('move project', () => {
|
||||
/**
|
||||
* Tries moving a library from ${lib}/data-access -> shared/${lib}/data-access
|
||||
@ -310,7 +58,7 @@ describe('Workspace Tests', () => {
|
||||
const lib1 = uniq('mylib');
|
||||
const lib2 = uniq('mylib');
|
||||
const lib3 = uniq('mylib');
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib1}/data-access`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib1}/data-access`);
|
||||
|
||||
updateFile(
|
||||
`libs/${lib1}/data-access/src/lib/${lib1}-data-access.ts`,
|
||||
@ -326,7 +74,7 @@ describe('Workspace Tests', () => {
|
||||
* Create a library which imports a class from lib1
|
||||
*/
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib2}/ui`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib2}/ui`);
|
||||
|
||||
updateFile(
|
||||
`libs/${lib2}/ui/src/lib/${lib2}-ui.ts`,
|
||||
@ -339,7 +87,7 @@ describe('Workspace Tests', () => {
|
||||
* Create a library which has an implicit dependency on lib1
|
||||
*/
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib3}`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib3}`);
|
||||
updateProjectConfig(lib3, (config) => {
|
||||
config.implicitDependencies = [`${lib1}-data-access`];
|
||||
return config;
|
||||
@ -446,7 +194,7 @@ describe('Workspace Tests', () => {
|
||||
const lib2 = uniq('mylib');
|
||||
const lib3 = uniq('mylib');
|
||||
runCLI(
|
||||
`generate @nrwl/workspace:lib ${lib1}/data-access --importPath=${importPath}`
|
||||
`generate @nrwl/js:lib ${lib1}/data-access --importPath=${importPath}`
|
||||
);
|
||||
|
||||
updateFile(
|
||||
@ -463,7 +211,7 @@ describe('Workspace Tests', () => {
|
||||
* Create a library which imports a class from lib1
|
||||
*/
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib2}/ui`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib2}/ui`);
|
||||
|
||||
updateFile(
|
||||
`libs/${lib2}/ui/src/lib/${lib2}-ui.ts`,
|
||||
@ -476,7 +224,7 @@ describe('Workspace Tests', () => {
|
||||
* Create a library which has an implicit dependency on lib1
|
||||
*/
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib3}`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib3}`);
|
||||
updateProjectConfig(lib3, (config) => {
|
||||
config.implicitDependencies = [`${lib1}-data-access`];
|
||||
return config;
|
||||
@ -579,7 +327,7 @@ describe('Workspace Tests', () => {
|
||||
nxJson.workspaceLayout = { libsDir: 'packages' };
|
||||
updateFile('nx.json', JSON.stringify(nxJson));
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib1}/data-access`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib1}/data-access`);
|
||||
|
||||
updateFile(
|
||||
`packages/${lib1}/data-access/src/lib/${lib1}-data-access.ts`,
|
||||
@ -595,7 +343,7 @@ describe('Workspace Tests', () => {
|
||||
* Create a library which imports a class from lib1
|
||||
*/
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib2}/ui`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib2}/ui`);
|
||||
|
||||
updateFile(
|
||||
`packages/${lib2}/ui/src/lib/${lib2}-ui.ts`,
|
||||
@ -608,7 +356,7 @@ describe('Workspace Tests', () => {
|
||||
* Create a library which has an implicit dependency on lib1
|
||||
*/
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib3}`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib3}`);
|
||||
updateProjectConfig(lib3, (config) => {
|
||||
config.implicitDependencies = [`${lib1}-data-access`];
|
||||
return config;
|
||||
@ -707,7 +455,7 @@ describe('Workspace Tests', () => {
|
||||
const lib1 = uniq('lib1');
|
||||
const lib2 = uniq('lib2');
|
||||
const lib3 = uniq('lib3');
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib1}`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib1}`);
|
||||
|
||||
updateFile(
|
||||
`libs/${lib1}/src/lib/${lib1}.ts`,
|
||||
@ -723,7 +471,7 @@ describe('Workspace Tests', () => {
|
||||
* Create a library which imports a class from lib1
|
||||
*/
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib2}/ui`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib2}/ui`);
|
||||
|
||||
updateFile(
|
||||
`libs/${lib2}/ui/src/lib/${lib2}-ui.ts`,
|
||||
@ -736,7 +484,7 @@ describe('Workspace Tests', () => {
|
||||
* Create a library which has an implicit dependency on lib1
|
||||
*/
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib3}`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib3}`);
|
||||
updateProjectConfig(lib3, (config) => {
|
||||
config.implicitDependencies = [lib1];
|
||||
return config;
|
||||
@ -841,7 +589,7 @@ describe('Workspace Tests', () => {
|
||||
const lib1 = uniq('mylib');
|
||||
const lib2 = uniq('mylib');
|
||||
const lib3 = uniq('mylib');
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib1}/data-access`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib1}/data-access`);
|
||||
let rootTsConfig = readJson('tsconfig.base.json');
|
||||
expect(
|
||||
rootTsConfig.compilerOptions.paths[`@${proj}/${lib1}/data-access`]
|
||||
@ -864,7 +612,7 @@ describe('Workspace Tests', () => {
|
||||
* Create a library which imports a class from lib1
|
||||
*/
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib2}/ui`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib2}/ui`);
|
||||
|
||||
updateFile(
|
||||
`libs/${lib2}/ui/src/lib/${lib2}-ui.ts`,
|
||||
@ -877,7 +625,7 @@ describe('Workspace Tests', () => {
|
||||
* Create a library which has an implicit dependency on lib1
|
||||
*/
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib3}`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib3}`);
|
||||
updateProjectConfig(lib3, (config) => {
|
||||
config.implicitDependencies = [`${lib1}-data-access`];
|
||||
return config;
|
||||
@ -955,14 +703,14 @@ describe('Workspace Tests', () => {
|
||||
const lib1 = uniq('myliba');
|
||||
const lib2 = uniq('mylibb');
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib1}`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib1}`);
|
||||
expect(exists(tmpProjPath(`libs/${lib1}`))).toBeTruthy();
|
||||
|
||||
/**
|
||||
* Create a library which has an implicit dependency on lib1
|
||||
*/
|
||||
|
||||
runCLI(`generate @nrwl/workspace:lib ${lib2}`);
|
||||
runCLI(`generate @nrwl/js:lib ${lib2}`);
|
||||
updateProjectConfig(lib2, (config) => {
|
||||
config.implicitDependencies = [lib1];
|
||||
return config;
|
||||
@ -1008,3 +756,180 @@ describe('Workspace Tests', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('workspace-generator', () => {
|
||||
const packageManager = getSelectedPackageManager() || 'pnpm';
|
||||
const proj = uniq('workspace');
|
||||
|
||||
beforeAll(() => {
|
||||
runCreateWorkspace(proj, {
|
||||
preset: 'ts',
|
||||
packageManager,
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => cleanupProject());
|
||||
|
||||
let custom: string;
|
||||
let failing: string;
|
||||
|
||||
beforeEach(() => {
|
||||
custom = uniq('custom');
|
||||
failing = uniq('custom-failing');
|
||||
runCLI(`g @nrwl/workspace:workspace-generator ${custom} --no-interactive`);
|
||||
runCLI(`g @nrwl/workspace:workspace-generator ${failing} --no-interactive`);
|
||||
|
||||
checkFilesExist(
|
||||
`tools/generators/${custom}/index.ts`,
|
||||
`tools/generators/${custom}/schema.json`
|
||||
);
|
||||
checkFilesExist(
|
||||
`tools/generators/${failing}/index.ts`,
|
||||
`tools/generators/${failing}/schema.json`
|
||||
);
|
||||
});
|
||||
|
||||
it('should compile only generator files with dependencies', () => {
|
||||
const workspace = uniq('workspace');
|
||||
|
||||
updateFile(
|
||||
'tools/utils/command-line-utils.ts',
|
||||
`
|
||||
export const noop = () => {}
|
||||
`
|
||||
);
|
||||
updateFile(
|
||||
'tools/utils/logger.ts',
|
||||
`
|
||||
export const log = (...args: any[]) => console.log(...args)
|
||||
`
|
||||
);
|
||||
updateFile(
|
||||
`tools/generators/utils.ts`,
|
||||
`
|
||||
export const noop = ()=>{}
|
||||
`
|
||||
);
|
||||
updateFile(`tools/generators/${custom}/index.ts`, (content) => {
|
||||
return `
|
||||
import { log } from '../../utils/logger'; \n
|
||||
${content}
|
||||
`;
|
||||
});
|
||||
|
||||
runCLI(`workspace-generator ${custom} ${workspace} --no-interactive -d`);
|
||||
|
||||
expect(() =>
|
||||
checkFilesExist(
|
||||
`dist/out-tsc/tools/generators/${custom}/index.js`,
|
||||
`dist/out-tsc/tools/generators/utils.js`,
|
||||
`dist/out-tsc/tools/utils/logger.js`
|
||||
)
|
||||
).not.toThrow();
|
||||
expect(() =>
|
||||
checkFilesExist(`dist/out-tsc/tools/utils/utils.js`)
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it('should support workspace-specific generators', async () => {
|
||||
const json = readJson(`tools/generators/${custom}/schema.json`);
|
||||
json.properties['directory'] = {
|
||||
type: 'string',
|
||||
description: 'lib directory',
|
||||
};
|
||||
json.properties['skipTsConfig'] = {
|
||||
type: 'boolean',
|
||||
description: 'skip changes to tsconfig',
|
||||
};
|
||||
json.properties['inlineprop'] = json.properties['name'];
|
||||
json.required = ['inlineprop'];
|
||||
delete json.properties['name'];
|
||||
|
||||
updateFile(`tools/generators/${custom}/schema.json`, JSON.stringify(json));
|
||||
|
||||
const indexFile = readFile(`tools/generators/${custom}/index.ts`);
|
||||
updateFile(
|
||||
`tools/generators/${custom}/index.ts`,
|
||||
indexFile.replace(
|
||||
'name: schema.name',
|
||||
'name: schema.inlineprop, directory: schema.directory, skipTsConfig: schema.skipTsConfig'
|
||||
)
|
||||
);
|
||||
|
||||
const helpOutput = runCLI(`workspace-generator ${custom} --help`);
|
||||
expect(helpOutput).toContain(
|
||||
`workspace-generator ${custom} [inlineprop] (options)`
|
||||
);
|
||||
expect(helpOutput).toContain(`--directory`);
|
||||
expect(helpOutput).toContain(`--skipTsConfig`);
|
||||
|
||||
const workspace = uniq('workspace');
|
||||
const dryRunOutput = runCLI(
|
||||
`workspace-generator ${custom} ${workspace} --no-interactive --directory=dir --skipTsConfig=true -d`
|
||||
);
|
||||
expect(exists(`packages/dir/${workspace}/src/index.ts`)).toEqual(false);
|
||||
expect(dryRunOutput).toContain(
|
||||
`CREATE packages/dir/${workspace}/src/index.ts`
|
||||
);
|
||||
|
||||
runCLI(
|
||||
`workspace-generator ${custom} ${workspace} --no-interactive --directory=dir`
|
||||
);
|
||||
checkFilesExist(`packages/dir/${workspace}/src/index.ts`);
|
||||
|
||||
const jsonFailing = readJson(`tools/generators/${failing}/schema.json`);
|
||||
jsonFailing.properties = {};
|
||||
jsonFailing.required = [];
|
||||
updateFile(
|
||||
`tools/generators/${failing}/schema.json`,
|
||||
JSON.stringify(jsonFailing)
|
||||
);
|
||||
|
||||
updateFile(
|
||||
`tools/generators/${failing}/index.ts`,
|
||||
`
|
||||
export default function() {
|
||||
throw new Error();
|
||||
}
|
||||
`
|
||||
);
|
||||
|
||||
try {
|
||||
await runCLI(`workspace-generator ${failing} --no-interactive`);
|
||||
fail(`Should exit 1 for a workspace-generator that throws an error`);
|
||||
} catch (e) {}
|
||||
|
||||
const listOutput = runCLI('workspace-generator --list-generators');
|
||||
expect(listOutput).toContain(custom);
|
||||
expect(listOutput).toContain(failing);
|
||||
}, 1000000);
|
||||
|
||||
it('should support angular devkit schematics', () => {
|
||||
const angularDevkitSchematic = uniq('angular-devkit-schematic');
|
||||
runCLI(
|
||||
`g @nrwl/workspace:workspace-generator ${angularDevkitSchematic} --no-interactive`
|
||||
);
|
||||
|
||||
const json = readJson(
|
||||
`tools/generators/${angularDevkitSchematic}/schema.json`
|
||||
);
|
||||
json.properties = {};
|
||||
json.required = [];
|
||||
delete json.cli;
|
||||
updateFile(
|
||||
`tools/generators/${angularDevkitSchematic}/schema.json`,
|
||||
JSON.stringify(json)
|
||||
);
|
||||
|
||||
updateFile(
|
||||
`tools/generators/${angularDevkitSchematic}/index.ts`,
|
||||
`
|
||||
export default function() {
|
||||
return (tree) => tree;
|
||||
}
|
||||
`
|
||||
);
|
||||
|
||||
runCLI(`workspace-generator ${angularDevkitSchematic} --no-interactive`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -144,7 +144,7 @@ describe('cache', () => {
|
||||
|
||||
it('should support using globs as outputs', async () => {
|
||||
const mylib = uniq('mylib');
|
||||
runCLI(`generate @nrwl/workspace:library ${mylib}`);
|
||||
runCLI(`generate @nrwl/js:library ${mylib}`);
|
||||
updateProjectConfig(mylib, (c) => {
|
||||
c.targets.build = {
|
||||
executor: 'nx:run-commands',
|
||||
|
||||
@ -1,24 +1,12 @@
|
||||
import {
|
||||
checkFilesExist,
|
||||
cleanupProject,
|
||||
fileExists,
|
||||
isWindows,
|
||||
newProject,
|
||||
readFile,
|
||||
readJson,
|
||||
readProjectConfig,
|
||||
removeFile,
|
||||
runCLI,
|
||||
runCLIAsync,
|
||||
runCommand,
|
||||
tmpProjPath,
|
||||
uniq,
|
||||
updateFile,
|
||||
updateJson,
|
||||
updateProjectConfig,
|
||||
} from '@nrwl/e2e/utils';
|
||||
import { PackageJson } from 'nx/src/utils/package-json';
|
||||
import * as path from 'path';
|
||||
|
||||
describe('Invoke Runner', () => {
|
||||
let proj: string;
|
||||
@ -27,7 +15,7 @@ describe('Invoke Runner', () => {
|
||||
|
||||
it('should invoke runner imperatively ', async () => {
|
||||
const mylib = uniq('mylib');
|
||||
runCLI(`generate @nrwl/workspace:lib ${mylib}`);
|
||||
runCLI(`generate @nrwl/js:lib ${mylib}`);
|
||||
updateProjectConfig(mylib, (c) => {
|
||||
c.targets['prebuild'] = {
|
||||
command: 'echo prebuild',
|
||||
@ -41,15 +29,15 @@ describe('Invoke Runner', () => {
|
||||
updateFile(
|
||||
'runner.js',
|
||||
`
|
||||
const { initTasksRunner } = require('nx/src/index');
|
||||
|
||||
const { initTasksRunner } = require('nx/src/index');
|
||||
|
||||
async function main(){
|
||||
const r = await initTasksRunner({});
|
||||
|
||||
|
||||
await r.invoke({tasks: [{id: '${mylib}:prebuild', target: {project: '${mylib}', target: 'prebuild'}, overrides: {__overrides_unparsed__: ''}}]});
|
||||
await r.invoke({tasks: [{id: '${mylib}:build', target: {project: '${mylib}', target: 'build'}, overrides: {__overrides_unparsed__: ''}}]});
|
||||
}
|
||||
|
||||
|
||||
main().then(q => {
|
||||
console.log("DONE")
|
||||
process.exit(0)
|
||||
|
||||
@ -29,7 +29,7 @@ describe('Nx Running Tests', () => {
|
||||
describe('(forwarding params)', () => {
|
||||
let proj = uniq('proj');
|
||||
beforeAll(() => {
|
||||
runCLI(`generate @nrwl/workspace:lib ${proj}`);
|
||||
runCLI(`generate @nrwl/js:lib ${proj}`);
|
||||
updateProjectConfig(proj, (c) => {
|
||||
c.targets['echo'] = {
|
||||
command: 'echo ECHO:',
|
||||
@ -333,8 +333,8 @@ describe('Nx Running Tests', () => {
|
||||
mylib1 = uniq('mylib1');
|
||||
mylib2 = uniq('mylib1');
|
||||
runCLI(`generate @nrwl/web:app ${myapp}`);
|
||||
runCLI(`generate @nrwl/web:lib ${mylib1} --buildable`);
|
||||
runCLI(`generate @nrwl/web:lib ${mylib2} --buildable`);
|
||||
runCLI(`generate @nrwl/js:lib ${mylib1}`);
|
||||
runCLI(`generate @nrwl/js:lib ${mylib2}`);
|
||||
|
||||
updateFile(
|
||||
`apps/${myapp}/src/main.ts`,
|
||||
|
||||
@ -15,7 +15,6 @@ type GeneratorsWithDefaultTests =
|
||||
| '@nrwl/react:app'
|
||||
| '@nrwl/next:app'
|
||||
| '@nrwl/angular:app'
|
||||
| '@nrwl/workspace:lib'
|
||||
| '@nrwl/web:app';
|
||||
|
||||
/**
|
||||
|
||||
@ -451,10 +451,6 @@ describe('nx-dev: Packages Section', () => {
|
||||
title: '@nrwl/workspace:new',
|
||||
path: '/packages/workspace/generators/new',
|
||||
},
|
||||
{
|
||||
title: '@nrwl/workspace:library',
|
||||
path: '/packages/workspace/generators/library',
|
||||
},
|
||||
{
|
||||
title: '@nrwl/workspace:workspace-generator',
|
||||
path: '/packages/workspace/generators/workspace-generator',
|
||||
|
||||
@ -11,7 +11,7 @@ import {
|
||||
} from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { cypressProjectGenerator } from '../../generators/cypress-project/cypress-project';
|
||||
import { libraryGenerator } from '@nrwl/workspace';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
|
||||
let projectGraph: ProjectGraph;
|
||||
jest.mock('@nrwl/devkit', () => {
|
||||
|
||||
@ -10,7 +10,7 @@ import {
|
||||
updateCyFile,
|
||||
updateCyMountUsage,
|
||||
} from './update-cy-mount-usage';
|
||||
import { libraryGenerator } from '@nrwl/workspace';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
import { cypressComponentProject } from '../../generators/cypress-component-project/cypress-component-project';
|
||||
|
||||
jest.mock('../../utils/cypress-version');
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { addProjectConfiguration, Tree } from '@nrwl/devkit';
|
||||
import { libraryGenerator } from '@nrwl/workspace';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import updateToCypress11 from './cypress-11';
|
||||
import { installedCypressVersion } from '../../utils/cypress-version';
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { readProjectConfiguration, Tree } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { Linter } from '@nrwl/linter';
|
||||
import { libraryGenerator } from '@nrwl/workspace/src/generators/library/library';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
import { addLinting } from './add-linting';
|
||||
|
||||
describe('Add Linting', () => {
|
||||
|
||||
@ -6,7 +6,7 @@ import {
|
||||
updateProjectConfiguration,
|
||||
} from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator as workspaceLib } from '@nrwl/workspace';
|
||||
import { libraryGenerator as workspaceLib } from '@nrwl/js';
|
||||
import jestInitGenerator from '../../generators/init/init';
|
||||
import { updateJestConfigExt } from './update-jest-config-ext';
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
readJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { createTree, createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator as workspaceLib } from '@nrwl/workspace';
|
||||
import { libraryGenerator as workspaceLib } from '@nrwl/js';
|
||||
import {
|
||||
updateExportsJestConfig,
|
||||
updateRootFiles,
|
||||
@ -172,8 +172,8 @@ module.exports = {
|
||||
stripIndents`
|
||||
const { getJestProjects } = require('@nrwl/jest');
|
||||
const nxPreset = require('@nrwl/jest/preset');
|
||||
|
||||
|
||||
|
||||
|
||||
const someFn = () => ({more: 'stuff'});
|
||||
module.export.abc = someFn;
|
||||
module.exports = {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { readJson, updateJson } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator as workspaceLib } from '@nrwl/workspace';
|
||||
import { libraryGenerator as workspaceLib } from '@nrwl/js';
|
||||
import {
|
||||
checkDeps,
|
||||
updateConfigsJest28,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator as workspaceLib } from '@nrwl/workspace';
|
||||
import { libraryGenerator as workspaceLib } from '@nrwl/js';
|
||||
import {
|
||||
readProjectConfiguration,
|
||||
updateProjectConfiguration,
|
||||
@ -139,10 +139,10 @@ describe('Jest Migration - jest 28 test files', () => {
|
||||
const { somethingElse } = require('ts-jest/utils');
|
||||
import * from ts from 'typescript'
|
||||
const mockTs = mocked(ts);
|
||||
|
||||
|
||||
describe('something expected', () => {
|
||||
it('should do something', () => {
|
||||
const actual = somethingExpected('abc');
|
||||
const actual = somethingExpected('abc');
|
||||
expect(1 + 1).toBe(2);
|
||||
});
|
||||
})
|
||||
@ -155,10 +155,10 @@ describe('Jest Migration - jest 28 test files', () => {
|
||||
const { somethingElse } = require('ts-jest/utils');
|
||||
import * from ts from 'typescript'
|
||||
const mockTs = mocked(ts);
|
||||
|
||||
|
||||
describe('something expected', () => {
|
||||
it('should do something', () => {
|
||||
const actual = somethingExpected('abc');
|
||||
const actual = somethingExpected('abc');
|
||||
expect(1 + 1).toBe(2);
|
||||
});
|
||||
})
|
||||
@ -176,7 +176,7 @@ describe('Jest Migration - jest 28 test files', () => {
|
||||
|
||||
describe('something expected', () => {
|
||||
it('should do something', () => {
|
||||
const actual = somethingExpected('abc');
|
||||
const actual = somethingExpected('abc');
|
||||
expect(1 + 1).toBe(2);
|
||||
});
|
||||
})
|
||||
@ -190,7 +190,7 @@ describe('Jest Migration - jest 28 test files', () => {
|
||||
|
||||
describe('something expected', () => {
|
||||
it('should do something', () => {
|
||||
const actual = somethingExpected('abc');
|
||||
const actual = somethingExpected('abc');
|
||||
expect(1 + 1).toBe(2);
|
||||
});
|
||||
})
|
||||
|
||||
@ -360,8 +360,8 @@ abc: [1234, true, {abc: 'yes'}] },
|
||||
exports[`Jest Migration - jest 29 update configs should work snapshotFormat is defined 2`] = `
|
||||
"module.exports = {
|
||||
transform: {
|
||||
'^.+\\\\\\\\.[tj]sx?$': ['ts-jest', {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
'^.+\\\\\\\\.[tj]sx?$': ['ts-jest', {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
}],
|
||||
},
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html']
|
||||
|
||||
@ -6,7 +6,7 @@ import {
|
||||
updateProjectConfiguration,
|
||||
} from '@nrwl/devkit';
|
||||
import { updateConfigsJest29 } from './update-configs-jest-29';
|
||||
import { libraryGenerator } from '@nrwl/workspace';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
|
||||
let projectGraph: ProjectGraph;
|
||||
jest.mock('@nrwl/devkit', () => ({
|
||||
@ -55,9 +55,9 @@ describe('Jest Migration - jest 29 update configs', () => {
|
||||
module.exports = {
|
||||
...nxPreset,
|
||||
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
|
||||
globals: {
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
},
|
||||
something: 'else',
|
||||
abc: [1234, true, {abc: 'yes'}]
|
||||
@ -307,8 +307,8 @@ module.exports = {
|
||||
'^.+\\\\.[tj]sx?$': 'babel-jest',
|
||||
},
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
},
|
||||
something: 'else',
|
||||
abc: [1234, true, {abc: 'yes'}]
|
||||
@ -331,8 +331,8 @@ module.exports = {
|
||||
testEnvironment: 'node',
|
||||
preset: '../../jest.preset.js',
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
},
|
||||
something: 'else',
|
||||
abc: [1234, true, {abc: 'yes'}]
|
||||
@ -430,9 +430,9 @@ transform: {
|
||||
},
|
||||
// I am a comment and shouldn't be removed
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
|
||||
globals: {
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
},
|
||||
something: 'else',
|
||||
abc: [1234, true, {abc: 'yes'}]
|
||||
|
||||
@ -5,7 +5,7 @@ import {
|
||||
updateProjectConfiguration,
|
||||
} from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator } from '@nrwl/workspace';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
import { updateTestsJest29 } from './update-tests-jest-29';
|
||||
|
||||
let projectGraph: ProjectGraph;
|
||||
@ -92,9 +92,9 @@ transform: {
|
||||
'^.+\\\\.[tj]sx?$': 'ts-jest'
|
||||
},
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
|
||||
globals: {
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
}
|
||||
},
|
||||
displayName: 'jest',
|
||||
|
||||
@ -434,6 +434,11 @@ function normalizeOptions(
|
||||
|
||||
options.bundler = options.bundler ?? options.compiler ?? 'tsc';
|
||||
|
||||
// ensure programmatic runs have an expected default
|
||||
if (!options.config) {
|
||||
options.config = 'project';
|
||||
}
|
||||
|
||||
if (options.publishable) {
|
||||
if (!options.importPath) {
|
||||
throw new Error(
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
updateProjectConfiguration,
|
||||
} from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator } from '@nrwl/workspace';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
import { defaultExclude } from '../../utils/swc/add-swc-config';
|
||||
import update from './update-swcrc';
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ import {
|
||||
import {
|
||||
addLint as addLintingToLibraryGenerator,
|
||||
NormalizedSchema as AddLintForLibrarySchema,
|
||||
} from '@nrwl/workspace/src/generators/library/library';
|
||||
} from '@nrwl/js/src/generators/library/library';
|
||||
import type { Linter } from 'eslint';
|
||||
|
||||
export async function conversionGenerator(
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import {
|
||||
getProjects,
|
||||
NxJsonConfiguration,
|
||||
readJson,
|
||||
readProjectConfiguration,
|
||||
Tree,
|
||||
@ -95,6 +94,9 @@ describe('lib', () => {
|
||||
const tsconfigJson = readJson(tree, 'libs/my-lib/tsconfig.json');
|
||||
expect(tsconfigJson).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"compilerOptions": Object {
|
||||
"module": "commonjs",
|
||||
},
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"files": Array [],
|
||||
"include": Array [],
|
||||
@ -461,9 +463,9 @@ describe('lib', () => {
|
||||
preset: '../../jest.preset.js',
|
||||
testEnvironment: 'node',
|
||||
transform: {
|
||||
'^.+\\\\\\\\.[tj]sx?$': 'babel-jest',
|
||||
'^.+\\\\\\\\.[tj]s$': 'babel-jest',
|
||||
},
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
||||
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||
coverageDirectory: '../../coverage/libs/my-lib',
|
||||
};
|
||||
"
|
||||
@ -486,6 +488,7 @@ describe('lib', () => {
|
||||
readJson(tree, 'libs/my-lib/tsconfig.json').compilerOptions
|
||||
).toEqual({
|
||||
allowJs: true,
|
||||
module: 'commonjs',
|
||||
});
|
||||
expect(readJson(tree, 'libs/my-lib/tsconfig.lib.json').include).toEqual([
|
||||
'src/**/*.ts',
|
||||
|
||||
@ -17,7 +17,7 @@ import {
|
||||
} from '@nrwl/devkit';
|
||||
import { getImportPath } from 'nx/src/utils/path';
|
||||
import { Schema } from './schema';
|
||||
import { libraryGenerator as workspaceLibraryGenerator } from '@nrwl/workspace/generators';
|
||||
import { libraryGenerator as jsLibraryGenerator } from '@nrwl/js';
|
||||
|
||||
import { join } from 'path';
|
||||
import { addSwcDependencies } from '@nrwl/js/src/utils/swc/add-swc-dependencies';
|
||||
@ -49,8 +49,10 @@ export async function libraryGenerator(tree: Tree, schema: Schema) {
|
||||
);
|
||||
}
|
||||
|
||||
const libraryInstall = await workspaceLibraryGenerator(tree, {
|
||||
const libraryInstall = await jsLibraryGenerator(tree, {
|
||||
...schema,
|
||||
bundler: schema.buildable ? 'tsc' : 'none',
|
||||
includeBabelRc: schema.babelJest,
|
||||
importPath: options.importPath,
|
||||
testEnvironment: 'node',
|
||||
skipFormat: true,
|
||||
|
||||
@ -360,8 +360,8 @@ abc: [1234, true, {abc: 'yes'}] },
|
||||
exports[`Nx Plugin Migration - jest 29 update configs should work snapshotFormat is defined 2`] = `
|
||||
"module.exports = {
|
||||
transform: {
|
||||
'^.+\\\\\\\\.[tj]sx?$': ['ts-jest', {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
'^.+\\\\\\\\.[tj]sx?$': ['ts-jest', {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
}],
|
||||
},
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html']
|
||||
|
||||
@ -6,7 +6,7 @@ import {
|
||||
updateProjectConfiguration,
|
||||
} from '@nrwl/devkit';
|
||||
import { updateConfigsJest29 } from './jest-29-configs';
|
||||
import { libraryGenerator } from '@nrwl/workspace';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
|
||||
let projectGraph: ProjectGraph;
|
||||
jest.mock('@nrwl/devkit', () => ({
|
||||
@ -55,9 +55,9 @@ describe('Nx Plugin Migration - jest 29 update configs', () => {
|
||||
module.exports = {
|
||||
...nxPreset,
|
||||
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
|
||||
globals: {
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
},
|
||||
something: 'else',
|
||||
abc: [1234, true, {abc: 'yes'}]
|
||||
@ -307,8 +307,8 @@ module.exports = {
|
||||
'^.+\\\\.[tj]sx?$': 'babel-jest',
|
||||
},
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
},
|
||||
something: 'else',
|
||||
abc: [1234, true, {abc: 'yes'}]
|
||||
@ -331,8 +331,8 @@ module.exports = {
|
||||
testEnvironment: 'node',
|
||||
preset: '../../jest.preset.js',
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
},
|
||||
something: 'else',
|
||||
abc: [1234, true, {abc: 'yes'}]
|
||||
@ -431,9 +431,9 @@ transform: {
|
||||
},
|
||||
// I am a comment and shouldn't be removed
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
|
||||
globals: {
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
},
|
||||
something: 'else',
|
||||
abc: [1234, true, {abc: 'yes'}]
|
||||
|
||||
@ -5,7 +5,7 @@ import {
|
||||
updateProjectConfiguration,
|
||||
} from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator } from '@nrwl/workspace';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
import { updateTestsJest29 } from './jest-29-tests';
|
||||
|
||||
let projectGraph: ProjectGraph;
|
||||
@ -92,9 +92,9 @@ transform: {
|
||||
'^.+\\\\.[tj]sx?$': 'ts-jest'
|
||||
},
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
|
||||
globals: {
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||
}
|
||||
},
|
||||
displayName: 'jest',
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import * as chalk from 'chalk';
|
||||
import { prompt } from 'enquirer';
|
||||
import { readJsonFile } from '../utils/fileutils';
|
||||
|
||||
import { readNxJson } from '../config/configuration';
|
||||
import { ProjectsConfigurations } from '../config/workspace-json-project-json';
|
||||
@ -234,10 +233,6 @@ async function convertToGenerateOptions(
|
||||
generatorName = 'new';
|
||||
}
|
||||
|
||||
if (!collectionName) {
|
||||
throwInvalidInvocation(['@nrwl/workspace:library']);
|
||||
}
|
||||
|
||||
const res = {
|
||||
collectionName,
|
||||
generatorName,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { readProjectConfiguration, Tree } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { Linter } from '@nrwl/linter';
|
||||
import { libraryGenerator } from '@nrwl/workspace/src/generators/library/library';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
import { addLinting } from './add-linting';
|
||||
|
||||
describe('Add Linting', () => {
|
||||
|
||||
@ -13,7 +13,7 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import * as enquirer from 'enquirer';
|
||||
|
||||
import { Linter } from '@nrwl/linter';
|
||||
import { libraryGenerator } from '@nrwl/workspace/generators';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
import { TsConfig } from '../../utils/utilities';
|
||||
import { storybook7Version } from '../../utils/versions';
|
||||
import configurationGenerator from './configuration';
|
||||
@ -44,7 +44,7 @@ describe('@nrwl/storybook:configuration for Storybook v7', () => {
|
||||
});
|
||||
await libraryGenerator(tree, {
|
||||
name: 'test-ui-lib',
|
||||
standaloneConfig: false,
|
||||
bundler: 'none',
|
||||
});
|
||||
writeJson(tree, 'package.json', {
|
||||
devDependencies: {
|
||||
@ -130,7 +130,6 @@ describe('@nrwl/storybook:configuration for Storybook v7', () => {
|
||||
await libraryGenerator(tree, {
|
||||
name: 'test-ui-lib2',
|
||||
linter: Linter.EsLint,
|
||||
standaloneConfig: false,
|
||||
});
|
||||
|
||||
updateJson(tree, 'libs/test-ui-lib2/.eslintrc.json', (json) => {
|
||||
@ -160,7 +159,6 @@ describe('@nrwl/storybook:configuration for Storybook v7', () => {
|
||||
await libraryGenerator(tree, {
|
||||
name: 'test-ui-lib2',
|
||||
linter: Linter.EsLint,
|
||||
standaloneConfig: false,
|
||||
});
|
||||
|
||||
await configurationGenerator(tree, {
|
||||
|
||||
@ -11,7 +11,7 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import * as enquirer from 'enquirer';
|
||||
|
||||
import { Linter } from '@nrwl/linter';
|
||||
import { libraryGenerator } from '@nrwl/workspace/generators';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
import { nxVersion } from '../../utils/versions';
|
||||
import { TsConfig } from '../../utils/utilities';
|
||||
import configurationGenerator from './configuration';
|
||||
|
||||
@ -2,7 +2,7 @@ import { installedCypressVersion } from '@nrwl/cypress/src/utils/cypress-version
|
||||
import { readJson, readProjectConfiguration, Tree } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { Linter } from '@nrwl/linter';
|
||||
import { libraryGenerator } from '@nrwl/workspace/generators';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
import { cypressProjectGenerator } from './cypress-project';
|
||||
|
||||
jest.mock('@nrwl/cypress/src/utils/cypress-version');
|
||||
|
||||
@ -5,7 +5,7 @@ import { Tree as NrwlTree } from '@nrwl/devkit';
|
||||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
|
||||
|
||||
import { createEmptyWorkspace } from '@nrwl/workspace/testing';
|
||||
import libraryGenerator from '@nrwl/workspace/src/generators/library/library';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
import { Linter } from '@nrwl/linter';
|
||||
|
||||
const testRunner = new SchematicTestRunner(
|
||||
@ -60,7 +60,6 @@ export async function createTestUILibNoNgDevkit(
|
||||
skipTsConfig: false,
|
||||
unitTestRunner: 'none',
|
||||
name: libName,
|
||||
standaloneConfig: false,
|
||||
});
|
||||
|
||||
return appTree;
|
||||
|
||||
@ -176,12 +176,6 @@ function setDefaults(tree: Tree, options: NormalizedSchema) {
|
||||
e2eTestRunner: options.e2eTestRunner,
|
||||
...nxJson.generators['@nrwl/web:application'],
|
||||
};
|
||||
nxJson.generators['@nrwl/web:library'] = {
|
||||
style: options.style,
|
||||
linter: options.linter,
|
||||
unitTestRunner: options.unitTestRunner,
|
||||
...nxJson.generators['@nrwl/web:library'],
|
||||
};
|
||||
updateNxJson(tree, nxJson);
|
||||
}
|
||||
|
||||
|
||||
@ -14,14 +14,6 @@
|
||||
"aliases": ["rm"],
|
||||
"description": "Remove an application or library."
|
||||
},
|
||||
"library": {
|
||||
"factory": "./src/generators/library/library#librarySchematic",
|
||||
"schema": "./src/generators/library/schema.json",
|
||||
"aliases": ["lib"],
|
||||
"x-type": "library",
|
||||
"description": "Create a library.",
|
||||
"x-deprecated": "Use @nrwl/js:lib instead. This will be removed in Nx v16"
|
||||
},
|
||||
"workspace-generator": {
|
||||
"factory": "./src/generators/workspace-generator/workspace-generator",
|
||||
"schema": "./src/generators/workspace-generator/schema.json",
|
||||
@ -67,14 +59,6 @@
|
||||
"description": "Create a workspace.",
|
||||
"hidden": true
|
||||
},
|
||||
"library": {
|
||||
"factory": "./src/generators/library/library#libraryGenerator",
|
||||
"schema": "./src/generators/library/schema.json",
|
||||
"aliases": ["lib"],
|
||||
"x-type": "library",
|
||||
"description": "Create a library.",
|
||||
"x-deprecated": "Use @nrwl/js:lib instead. This will be removed in Nx v16."
|
||||
},
|
||||
"workspace-generator": {
|
||||
"factory": "./src/generators/workspace-generator/workspace-generator",
|
||||
"schema": "./src/generators/workspace-generator/schema.json",
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
export { libraryGenerator } from './src/generators/library/library';
|
||||
export { npmPackageGenerator } from './src/generators/npm-package/npm-package';
|
||||
export { moveGenerator } from './src/generators/move/move';
|
||||
export { removeGenerator } from './src/generators/remove/remove';
|
||||
|
||||
@ -41,7 +41,6 @@ import * as strings from './src/utils/strings';
|
||||
// TODO(v17): Remove this export.
|
||||
export { checkAndCleanWithSemver } from './src/utils/version-utils';
|
||||
|
||||
export { libraryGenerator } from './src/generators/library/library';
|
||||
export { moveGenerator } from './src/generators/move/move';
|
||||
export { removeGenerator } from './src/generators/remove/remove';
|
||||
export { runCommandsGenerator } from './src/generators/run-commands/run-commands';
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
# <%= name %>
|
||||
|
||||
This library was generated with [Nx](https://nx.dev).
|
||||
<% if (hasUnitTestRunner) { %>
|
||||
|
||||
## Running unit tests
|
||||
|
||||
Run `<%= cliCommand %> test <%= name %>` to execute the unit tests via [Jest](https://jestjs.io).
|
||||
<% } %><% if (hasLinter) { %>
|
||||
|
||||
## Running lint
|
||||
|
||||
Run `<%= cliCommand %> lint <%= name %>` to execute the lint via [ESLint](https://eslint.org/).
|
||||
<% } %>
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"presets": [["@nrwl/js/babel", { "useBuiltIns": "usage" }]]
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"name": "<%= importPath %>",
|
||||
"version": "0.0.1"
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
export * from './lib/<%= fileName %>';
|
||||
@ -1,7 +0,0 @@
|
||||
import { <%= propertyName %> } from './<%= fileName %>';
|
||||
|
||||
describe('<%= propertyName %>', () => {
|
||||
it('should work', () => {
|
||||
expect(<%= propertyName %>()).toEqual('<%= name %>');
|
||||
})
|
||||
})
|
||||
@ -1,3 +0,0 @@
|
||||
export function <%= propertyName %>(): string {
|
||||
return '<%= name %>';
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
{
|
||||
"extends": "<%= rootTsConfigPath %>",<% if (js) { %>
|
||||
"compilerOptions": {
|
||||
"allowJs": true
|
||||
},<% } %>
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.lib.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
||||
"declaration": true,
|
||||
"types": []
|
||||
},
|
||||
"include": ["src/**/*.ts"<% if (js) { %>, "src/**/*.js"<% } %>],
|
||||
"exclude": ["jest.config.ts","src/**/*.spec.ts"<% if (js) { %>, "src/**/*.spec.js"<% } %>]
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"rootDir": ".",
|
||||
"sourceMap": true,
|
||||
"declaration": false,
|
||||
"moduleResolution": "node",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"importHelpers": true,
|
||||
"target": "es2015",
|
||||
"module": "esnext",
|
||||
"lib": ["es2017", "dom"],
|
||||
"skipLibCheck": true,
|
||||
"skipDefaultLibCheck": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {}
|
||||
},
|
||||
"exclude": ["node_modules", "tmp"]
|
||||
}
|
||||
@ -1,804 +0,0 @@
|
||||
import {
|
||||
getProjects,
|
||||
readJson,
|
||||
readProjectConfiguration,
|
||||
Tree,
|
||||
updateJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
|
||||
import { libraryGenerator } from './library';
|
||||
import { Schema } from './schema.d';
|
||||
|
||||
describe('lib', () => {
|
||||
let tree: Tree;
|
||||
const defaultOptions: Omit<Schema, 'name'> = {
|
||||
skipTsConfig: false,
|
||||
unitTestRunner: 'jest',
|
||||
skipFormat: false,
|
||||
linter: 'eslint',
|
||||
simpleModuleName: false,
|
||||
testEnvironment: 'jsdom',
|
||||
js: false,
|
||||
pascalCaseFiles: false,
|
||||
strict: true,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
||||
});
|
||||
|
||||
describe('not nested', () => {
|
||||
it('should create project configuration', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
});
|
||||
|
||||
const config = readProjectConfiguration(tree, 'my-lib');
|
||||
expect(config.root).toEqual('libs/my-lib');
|
||||
expect(config.targets.build).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should update tags', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
tags: 'one,two',
|
||||
});
|
||||
const projects = Object.fromEntries(getProjects(tree));
|
||||
expect(projects).toMatchObject({
|
||||
'my-lib': {
|
||||
tags: ['one', 'two'],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should update root tsconfig.base.json', async () => {
|
||||
await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' });
|
||||
const tsconfigJson = readJson(tree, '/tsconfig.base.json');
|
||||
expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([
|
||||
'libs/my-lib/src/index.ts',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should update root tsconfig.json when no tsconfig.base.json', async () => {
|
||||
tree.rename('tsconfig.base.json', 'tsconfig.json');
|
||||
|
||||
await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' });
|
||||
|
||||
const tsconfigJson = readJson(tree, '/tsconfig.json');
|
||||
expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([
|
||||
'libs/my-lib/src/index.ts',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should update root tsconfig.json (no existing path mappings)', async () => {
|
||||
updateJson(tree, 'tsconfig.base.json', (json) => {
|
||||
json.compilerOptions.paths = undefined;
|
||||
return json;
|
||||
});
|
||||
|
||||
await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' });
|
||||
const tsconfigJson = readJson(tree, '/tsconfig.base.json');
|
||||
expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([
|
||||
'libs/my-lib/src/index.ts',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should create a local tsconfig.json', async () => {
|
||||
await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' });
|
||||
const tsconfigJson = readJson(tree, 'libs/my-lib/tsconfig.json');
|
||||
expect(tsconfigJson).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"compilerOptions": Object {
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitReturns": true,
|
||||
"strict": true,
|
||||
},
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"files": Array [],
|
||||
"include": Array [],
|
||||
"references": Array [
|
||||
Object {
|
||||
"path": "./tsconfig.lib.json",
|
||||
},
|
||||
Object {
|
||||
"path": "./tsconfig.spec.json",
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('should extend from root tsconfig.json when no tsconfig.base.json', async () => {
|
||||
tree.rename('tsconfig.base.json', 'tsconfig.json');
|
||||
|
||||
await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' });
|
||||
|
||||
const tsconfigJson = readJson(tree, 'libs/my-lib/tsconfig.json');
|
||||
expect(tsconfigJson.extends).toBe('../../tsconfig.json');
|
||||
});
|
||||
|
||||
it('should extend the local tsconfig.json with tsconfig.spec.json', async () => {
|
||||
await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' });
|
||||
const tsconfigJson = readJson(tree, 'libs/my-lib/tsconfig.spec.json');
|
||||
expect(tsconfigJson.extends).toEqual('./tsconfig.json');
|
||||
});
|
||||
|
||||
it('should extend the local tsconfig.json with tsconfig.lib.json', async () => {
|
||||
await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' });
|
||||
const tsconfigJson = readJson(tree, 'libs/my-lib/tsconfig.lib.json');
|
||||
expect(tsconfigJson.extends).toEqual('./tsconfig.json');
|
||||
});
|
||||
|
||||
it('should generate files', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
});
|
||||
|
||||
expect(tree.exists(`libs/my-lib/jest.config.ts`)).toBeTruthy();
|
||||
expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8'))
|
||||
.toMatchInlineSnapshot(`
|
||||
"/* eslint-disable */
|
||||
export default {
|
||||
displayName: 'my-lib',
|
||||
preset: '../../jest.preset.js',
|
||||
transform: {
|
||||
'^.+\\\\\\\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
||||
},
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
||||
coverageDirectory: '../../coverage/libs/my-lib',
|
||||
};
|
||||
"
|
||||
`);
|
||||
expect(tree.exists('libs/my-lib/src/index.ts')).toBeTruthy();
|
||||
expect(tree.exists('libs/my-lib/src/lib/my-lib.ts')).toBeTruthy();
|
||||
expect(tree.exists('libs/my-lib/src/lib/my-lib.spec.ts')).toBeTruthy();
|
||||
expect(tree.exists('libs/my-lib/README.md')).toBeTruthy();
|
||||
expect(tree.exists('libs/my-lib/package.json')).toBeFalsy();
|
||||
|
||||
const ReadmeContent = tree.read('libs/my-lib/README.md', 'utf-8');
|
||||
expect(ReadmeContent).toContain('nx test my-lib');
|
||||
});
|
||||
|
||||
it('should add project to the jest config', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
});
|
||||
|
||||
expect(tree.read('jest.config.ts', 'utf-8')).toMatchInlineSnapshot(
|
||||
`
|
||||
"import { getJestProjects } from '@nrwl/jest';
|
||||
|
||||
export default {
|
||||
projects: getJestProjects(),
|
||||
};
|
||||
"
|
||||
`
|
||||
);
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib2',
|
||||
});
|
||||
|
||||
expect(tree.read('jest.config.ts', 'utf-8')).toMatchInlineSnapshot(
|
||||
`
|
||||
"import { getJestProjects } from '@nrwl/jest';
|
||||
|
||||
export default {
|
||||
projects: getJestProjects(),
|
||||
};
|
||||
"
|
||||
`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('nested', () => {
|
||||
it('should update tags', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
tags: 'one',
|
||||
});
|
||||
let projects = Object.fromEntries(getProjects(tree));
|
||||
expect(projects).toMatchObject({
|
||||
'my-dir-my-lib': {
|
||||
tags: ['one'],
|
||||
},
|
||||
});
|
||||
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib2',
|
||||
directory: 'myDir',
|
||||
tags: 'one,two',
|
||||
simpleModuleName: true,
|
||||
});
|
||||
projects = Object.fromEntries(getProjects(tree));
|
||||
expect(projects).toMatchObject({
|
||||
'my-dir-my-lib': {
|
||||
tags: ['one'],
|
||||
},
|
||||
'my-dir-my-lib2': {
|
||||
tags: ['one', 'two'],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should generate files', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
});
|
||||
expect(tree.exists(`libs/my-dir/my-lib/jest.config.ts`)).toBeTruthy();
|
||||
expect(tree.exists('libs/my-dir/my-lib/src/index.ts')).toBeTruthy();
|
||||
expect(
|
||||
tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.ts')
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.spec.ts')
|
||||
).toBeTruthy();
|
||||
expect(tree.exists('libs/my-dir/my-lib/src/index.ts')).toBeTruthy();
|
||||
expect(tree.exists(`libs/my-dir/my-lib/.eslintrc.json`)).toBeTruthy();
|
||||
expect(tree.exists(`libs/my-dir/my-lib/package.json`)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should create project configurations', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
});
|
||||
|
||||
const config = readProjectConfiguration(tree, 'my-dir-my-lib');
|
||||
expect(config.root).toEqual('libs/my-dir/my-lib');
|
||||
expect(config.targets.lint).toEqual({
|
||||
executor: '@nrwl/linter:eslint',
|
||||
outputs: ['{options.outputFile}'],
|
||||
options: {
|
||||
lintFilePatterns: ['libs/my-dir/my-lib/**/*.ts'],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should update root tsconfig.base.json', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
});
|
||||
const tsconfigJson = readJson(tree, '/tsconfig.base.json');
|
||||
expect(tsconfigJson.compilerOptions.paths['@proj/my-dir/my-lib']).toEqual(
|
||||
['libs/my-dir/my-lib/src/index.ts']
|
||||
);
|
||||
expect(
|
||||
tsconfigJson.compilerOptions.paths['my-dir-my-lib/*']
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should update root tsconfig.json when no tsconfig.base.json', async () => {
|
||||
tree.rename('tsconfig.base.json', 'tsconfig.json');
|
||||
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
});
|
||||
|
||||
const tsconfigJson = readJson(tree, '/tsconfig.json');
|
||||
expect(tsconfigJson.compilerOptions.paths['@proj/my-dir/my-lib']).toEqual(
|
||||
['libs/my-dir/my-lib/src/index.ts']
|
||||
);
|
||||
expect(
|
||||
tsconfigJson.compilerOptions.paths['my-dir-my-lib/*']
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should create a local tsconfig.json', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
});
|
||||
|
||||
const tsconfigJson = readJson(tree, 'libs/my-dir/my-lib/tsconfig.json');
|
||||
expect(tsconfigJson.extends).toBe('../../../tsconfig.base.json');
|
||||
expect(tsconfigJson.references).toEqual([
|
||||
{
|
||||
path: './tsconfig.lib.json',
|
||||
},
|
||||
{
|
||||
path: './tsconfig.spec.json',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should extend from root tsconfig.json when no tsconfig.base.json', async () => {
|
||||
tree.rename('tsconfig.base.json', 'tsconfig.json');
|
||||
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
});
|
||||
|
||||
const tsconfigJson = readJson(tree, 'libs/my-dir/my-lib/tsconfig.json');
|
||||
expect(tsconfigJson.extends).toBe('../../../tsconfig.json');
|
||||
});
|
||||
});
|
||||
|
||||
describe('--linter', () => {
|
||||
describe('eslint', () => {
|
||||
it('should add eslint dependencies', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
});
|
||||
|
||||
const packageJson = readJson(tree, 'package.json');
|
||||
expect(packageJson.devDependencies['eslint']).toBeDefined();
|
||||
expect(packageJson.devDependencies['@nrwl/linter']).toBeDefined();
|
||||
expect(
|
||||
packageJson.devDependencies['@nrwl/eslint-plugin-nx']
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
describe('not nested', () => {
|
||||
it('should create project configurations', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
});
|
||||
|
||||
expect(readProjectConfiguration(tree, 'my-lib').targets.lint).toEqual(
|
||||
{
|
||||
executor: '@nrwl/linter:eslint',
|
||||
outputs: ['{options.outputFile}'],
|
||||
options: {
|
||||
lintFilePatterns: ['libs/my-lib/**/*.ts'],
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should create a local .eslintrc.json', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
});
|
||||
|
||||
const eslintJson = readJson(tree, 'libs/my-lib/.eslintrc.json');
|
||||
expect(eslintJson).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"extends": Array [
|
||||
"../../.eslintrc.json",
|
||||
],
|
||||
"ignorePatterns": Array [
|
||||
"!**/*",
|
||||
],
|
||||
"overrides": Array [
|
||||
Object {
|
||||
"files": Array [
|
||||
"*.ts",
|
||||
"*.tsx",
|
||||
"*.js",
|
||||
"*.jsx",
|
||||
],
|
||||
"rules": Object {},
|
||||
},
|
||||
Object {
|
||||
"files": Array [
|
||||
"*.ts",
|
||||
"*.tsx",
|
||||
],
|
||||
"rules": Object {},
|
||||
},
|
||||
Object {
|
||||
"files": Array [
|
||||
"*.js",
|
||||
"*.jsx",
|
||||
],
|
||||
"rules": Object {},
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('nested', () => {
|
||||
it('should create project configuration', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
});
|
||||
|
||||
expect(
|
||||
readProjectConfiguration(tree, 'my-dir-my-lib').targets.lint
|
||||
).toEqual({
|
||||
executor: '@nrwl/linter:eslint',
|
||||
outputs: ['{options.outputFile}'],
|
||||
options: {
|
||||
lintFilePatterns: ['libs/my-dir/my-lib/**/*.ts'],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a local .eslintrc.json', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
});
|
||||
|
||||
const eslintJson = readJson(
|
||||
tree,
|
||||
'libs/my-dir/my-lib/.eslintrc.json'
|
||||
);
|
||||
expect(eslintJson).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"extends": Array [
|
||||
"../../../.eslintrc.json",
|
||||
],
|
||||
"ignorePatterns": Array [
|
||||
"!**/*",
|
||||
],
|
||||
"overrides": Array [
|
||||
Object {
|
||||
"files": Array [
|
||||
"*.ts",
|
||||
"*.tsx",
|
||||
"*.js",
|
||||
"*.jsx",
|
||||
],
|
||||
"rules": Object {},
|
||||
},
|
||||
Object {
|
||||
"files": Array [
|
||||
"*.ts",
|
||||
"*.tsx",
|
||||
],
|
||||
"rules": Object {},
|
||||
},
|
||||
Object {
|
||||
"files": Array [
|
||||
"*.js",
|
||||
"*.jsx",
|
||||
],
|
||||
"rules": Object {},
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('--unit-test-runner none', () => {
|
||||
it('should not generate test configuration nor spec file', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
unitTestRunner: 'none',
|
||||
});
|
||||
|
||||
expect(tree.exists('libs/my-lib/tsconfig.spec.json')).toBeFalsy();
|
||||
expect(tree.exists('libs/my-lib/jest.config.ts')).toBeFalsy();
|
||||
expect(tree.exists('libs/my-lib/src/lib/my-lib.spec.ts')).toBeFalsy();
|
||||
|
||||
const config = readProjectConfiguration(tree, 'my-lib');
|
||||
expect(config.targets.test).toBeUndefined();
|
||||
expect(config.targets.lint).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"executor": "@nrwl/linter:eslint",
|
||||
"options": Object {
|
||||
"lintFilePatterns": Array [
|
||||
"libs/my-lib/**/*.ts",
|
||||
],
|
||||
},
|
||||
"outputs": Array [
|
||||
"{options.outputFile}",
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('--strict', () => {
|
||||
it('should update the projects tsconfig with strict false', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
strict: false,
|
||||
});
|
||||
const tsconfigJson = readJson(tree, '/libs/my-lib/tsconfig.json');
|
||||
|
||||
expect(tsconfigJson.compilerOptions?.strict).not.toBeDefined();
|
||||
expect(
|
||||
tsconfigJson.compilerOptions?.forceConsistentCasingInFileNames
|
||||
).not.toBeDefined();
|
||||
expect(tsconfigJson.compilerOptions?.noImplicitReturns).not.toBeDefined();
|
||||
expect(
|
||||
tsconfigJson.compilerOptions?.noFallthroughCasesInSwitch
|
||||
).not.toBeDefined();
|
||||
});
|
||||
|
||||
it('should default to strict true', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
});
|
||||
const tsconfigJson = readJson(tree, '/libs/my-lib/tsconfig.json');
|
||||
|
||||
expect(tsconfigJson.compilerOptions.strict).toBeTruthy();
|
||||
expect(
|
||||
tsconfigJson.compilerOptions.forceConsistentCasingInFileNames
|
||||
).toBeTruthy();
|
||||
expect(tsconfigJson.compilerOptions.noImplicitReturns).toBeTruthy();
|
||||
expect(
|
||||
tsconfigJson.compilerOptions.noFallthroughCasesInSwitch
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('--importPath', () => {
|
||||
it('should update the tsconfig with the given import path', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
importPath: '@myorg/lib',
|
||||
});
|
||||
const tsconfigJson = readJson(tree, '/tsconfig.base.json');
|
||||
|
||||
expect(tsconfigJson.compilerOptions.paths['@myorg/lib']).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail if the same importPath has already been used', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib1',
|
||||
importPath: '@myorg/lib',
|
||||
});
|
||||
|
||||
try {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib2',
|
||||
importPath: '@myorg/lib',
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e.message).toContain(
|
||||
'You already have a library using the import path'
|
||||
);
|
||||
}
|
||||
|
||||
expect.assertions(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('--js flag', () => {
|
||||
it('should generate js files instead of ts files', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
js: true,
|
||||
});
|
||||
expect(tree.exists(`libs/my-lib/jest.config.js`)).toBeTruthy();
|
||||
expect(tree.exists('libs/my-lib/src/index.js')).toBeTruthy();
|
||||
expect(tree.exists('libs/my-lib/src/lib/my-lib.js')).toBeTruthy();
|
||||
expect(tree.exists('libs/my-lib/src/lib/my-lib.spec.js')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should update tsconfig.json with compilerOptions.allowJs: true', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
js: true,
|
||||
});
|
||||
expect(
|
||||
readJson(tree, 'libs/my-lib/tsconfig.json').compilerOptions
|
||||
).toEqual({
|
||||
forceConsistentCasingInFileNames: true,
|
||||
noFallthroughCasesInSwitch: true,
|
||||
noImplicitReturns: true,
|
||||
strict: true,
|
||||
allowJs: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('should update tsconfig.lib.json include with **/*.js glob', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
js: true,
|
||||
});
|
||||
expect(readJson(tree, 'libs/my-lib/tsconfig.lib.json').include).toEqual([
|
||||
'src/**/*.ts',
|
||||
'src/**/*.js',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should update root tsconfig.json with a js file path', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
js: true,
|
||||
});
|
||||
const tsconfigJson = readJson(tree, '/tsconfig.base.json');
|
||||
expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([
|
||||
'libs/my-lib/src/index.js',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should generate js files for nested libs as well', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
js: true,
|
||||
});
|
||||
expect(tree.exists(`libs/my-dir/my-lib/jest.config.js`)).toBeTruthy();
|
||||
expect(tree.exists('libs/my-dir/my-lib/src/index.js')).toBeTruthy();
|
||||
expect(
|
||||
tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.js')
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.spec.js')
|
||||
).toBeTruthy();
|
||||
expect(tree.exists('libs/my-dir/my-lib/src/index.js')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should configure the project for linting js files', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
js: true,
|
||||
});
|
||||
expect(
|
||||
readProjectConfiguration(tree, 'my-dir-my-lib').targets.lint.options
|
||||
.lintFilePatterns
|
||||
).toEqual(['libs/my-dir/my-lib/**/*.js']);
|
||||
expect(readJson(tree, 'libs/my-dir/my-lib/.eslintrc.json'))
|
||||
.toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"extends": Array [
|
||||
"../../../.eslintrc.json",
|
||||
],
|
||||
"ignorePatterns": Array [
|
||||
"!**/*",
|
||||
],
|
||||
"overrides": Array [
|
||||
Object {
|
||||
"files": Array [
|
||||
"*.ts",
|
||||
"*.tsx",
|
||||
"*.js",
|
||||
"*.jsx",
|
||||
],
|
||||
"rules": Object {},
|
||||
},
|
||||
Object {
|
||||
"files": Array [
|
||||
"*.ts",
|
||||
"*.tsx",
|
||||
],
|
||||
"rules": Object {},
|
||||
},
|
||||
Object {
|
||||
"files": Array [
|
||||
"*.js",
|
||||
"*.jsx",
|
||||
],
|
||||
"rules": Object {},
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe(`--babelJest`, () => {
|
||||
it('should use babel for jest', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
babelJest: true,
|
||||
} as Schema);
|
||||
|
||||
expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8'))
|
||||
.toMatchInlineSnapshot(`
|
||||
"/* eslint-disable */
|
||||
export default {
|
||||
displayName: 'my-lib',
|
||||
preset: '../../jest.preset.js',
|
||||
transform: {
|
||||
'^.+\\\\\\\\.[tj]sx?$': 'babel-jest',
|
||||
},
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
||||
coverageDirectory: '../../coverage/libs/my-lib',
|
||||
};
|
||||
"
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('--pascalCaseFiles', () => {
|
||||
it('should generate files with upper case names', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
pascalCaseFiles: true,
|
||||
});
|
||||
expect(tree.exists('libs/my-lib/src/lib/MyLib.ts')).toBeTruthy();
|
||||
expect(tree.exists('libs/my-lib/src/lib/MyLib.spec.ts')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should generate files with upper case names for nested libs as well', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
directory: 'myDir',
|
||||
pascalCaseFiles: true,
|
||||
});
|
||||
expect(
|
||||
tree.exists('libs/my-dir/my-lib/src/lib/MyDirMyLib.ts')
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
tree.exists('libs/my-dir/my-lib/src/lib/MyDirMyLib.spec.ts')
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('--skipBabelrc', () => {
|
||||
it('should skip generating .babelrc when --skipBabelrc=true', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
skipBabelrc: true,
|
||||
});
|
||||
expect(tree.exists('libs/my-lib/.babelrc')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should generate .babelrc by default', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
});
|
||||
expect(tree.exists('libs/my-lib/.babelrc')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('--buildable', () => {
|
||||
it('should add build target', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
buildable: true,
|
||||
});
|
||||
expect(
|
||||
readProjectConfiguration(tree, 'my-lib').targets.build.executor
|
||||
).toBe('@nrwl/js:tsc');
|
||||
});
|
||||
|
||||
it('should generate a package.json file', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'myLib',
|
||||
buildable: true,
|
||||
});
|
||||
|
||||
expect(tree.exists('libs/my-lib/package.json')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,281 +0,0 @@
|
||||
import {
|
||||
addDependenciesToPackageJson,
|
||||
addProjectConfiguration,
|
||||
convertNxGenerator,
|
||||
ensurePackage,
|
||||
extractLayoutDirectory,
|
||||
formatFiles,
|
||||
generateFiles,
|
||||
GeneratorCallback,
|
||||
getWorkspaceLayout,
|
||||
joinPathFragments,
|
||||
names,
|
||||
offsetFromRoot,
|
||||
ProjectConfiguration,
|
||||
runTasksInSerial,
|
||||
toJS,
|
||||
Tree,
|
||||
updateJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { getImportPath } from 'nx/src/utils/path';
|
||||
import { join } from 'path';
|
||||
|
||||
import {
|
||||
getRelativePathToRootTsConfig,
|
||||
getRootTsConfigFileName,
|
||||
getRootTsConfigPathInTree,
|
||||
} from '../../utilities/ts-config';
|
||||
import { nxVersion, typescriptVersion } from '../../utils/versions';
|
||||
import type { Schema } from './schema';
|
||||
|
||||
export interface NormalizedSchema extends Schema {
|
||||
name: string;
|
||||
fileName: string;
|
||||
projectRoot: string;
|
||||
projectDirectory: string;
|
||||
libsDir: string;
|
||||
parsedTags: string[];
|
||||
importPath?: string;
|
||||
}
|
||||
|
||||
function addProject(tree: Tree, options: NormalizedSchema) {
|
||||
const projectConfiguration: ProjectConfiguration = {
|
||||
root: options.projectRoot,
|
||||
sourceRoot: joinPathFragments(options.projectRoot, 'src'),
|
||||
projectType: 'library',
|
||||
targets: {},
|
||||
tags: options.parsedTags,
|
||||
};
|
||||
|
||||
if (options.buildable) {
|
||||
addDependenciesToPackageJson(tree, {}, { '@nrwl/js': nxVersion });
|
||||
projectConfiguration.targets.build = {
|
||||
executor: '@nrwl/js:tsc',
|
||||
outputs: ['{options.outputPath}'],
|
||||
options: {
|
||||
outputPath:
|
||||
options.libsDir != '.'
|
||||
? `dist/${options.libsDir}/${options.projectDirectory}`
|
||||
: `dist/${options.projectDirectory}`,
|
||||
main: `${options.projectRoot}/src/index` + (options.js ? '.js' : '.ts'),
|
||||
tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
|
||||
assets: [`${options.projectRoot}/*.md`],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
addProjectConfiguration(tree, options.name, projectConfiguration);
|
||||
}
|
||||
|
||||
export async function addLint(
|
||||
tree: Tree,
|
||||
options: NormalizedSchema
|
||||
): Promise<GeneratorCallback> {
|
||||
const { lintProjectGenerator } = ensurePackage('@nrwl/linter', nxVersion);
|
||||
return lintProjectGenerator(tree, {
|
||||
project: options.name,
|
||||
linter: options.linter,
|
||||
skipFormat: true,
|
||||
tsConfigPaths: [
|
||||
joinPathFragments(options.projectRoot, 'tsconfig.lib.json'),
|
||||
],
|
||||
unitTestRunner: options.unitTestRunner,
|
||||
eslintFilePatterns: [
|
||||
`${options.projectRoot}/**/*.${options.js ? 'js' : 'ts'}`,
|
||||
],
|
||||
setParserOptionsProject: options.setParserOptionsProject,
|
||||
});
|
||||
}
|
||||
|
||||
function updateTsConfig(tree: Tree, options: NormalizedSchema) {
|
||||
updateJson(tree, join(options.projectRoot, 'tsconfig.json'), (json) => {
|
||||
if (options.strict) {
|
||||
json.compilerOptions = {
|
||||
...json.compilerOptions,
|
||||
forceConsistentCasingInFileNames: true,
|
||||
strict: true,
|
||||
noImplicitReturns: true,
|
||||
noFallthroughCasesInSwitch: true,
|
||||
};
|
||||
}
|
||||
|
||||
return json;
|
||||
});
|
||||
}
|
||||
|
||||
function updateRootTsConfig(host: Tree, options: NormalizedSchema) {
|
||||
updateJson(host, getRootTsConfigPathInTree(host), (json) => {
|
||||
const c = json.compilerOptions;
|
||||
c.paths = c.paths || {};
|
||||
delete c.paths[options.name];
|
||||
|
||||
if (c.paths[options.importPath]) {
|
||||
throw new Error(
|
||||
`You already have a library using the import path "${options.importPath}". Make sure to specify a unique one.`
|
||||
);
|
||||
}
|
||||
|
||||
c.paths[options.importPath] = [
|
||||
joinPathFragments(
|
||||
options.projectRoot,
|
||||
'./src',
|
||||
'index.' + (options.js ? 'js' : 'ts')
|
||||
),
|
||||
];
|
||||
|
||||
return json;
|
||||
});
|
||||
}
|
||||
|
||||
function createFiles(tree: Tree, options: NormalizedSchema) {
|
||||
const { className, name, propertyName } = names(options.name);
|
||||
|
||||
const rootOffset = offsetFromRoot(options.projectRoot);
|
||||
generateFiles(tree, join(__dirname, './files/lib'), options.projectRoot, {
|
||||
...options,
|
||||
dot: '.',
|
||||
className,
|
||||
name,
|
||||
propertyName,
|
||||
js: !!options.js,
|
||||
cliCommand: 'nx',
|
||||
strict: undefined,
|
||||
tmpl: '',
|
||||
offsetFromRoot: rootOffset,
|
||||
rootTsConfigPath: getRelativePathToRootTsConfig(tree, options.projectRoot),
|
||||
hasUnitTestRunner: options.unitTestRunner !== 'none',
|
||||
hasLinter: options.linter !== 'none',
|
||||
});
|
||||
|
||||
if (options.unitTestRunner === 'none') {
|
||||
tree.delete(
|
||||
join(options.projectRoot, 'src/lib', `${options.fileName}.spec.ts`)
|
||||
);
|
||||
}
|
||||
|
||||
if (options.skipBabelrc) {
|
||||
tree.delete(join(options.projectRoot, '.babelrc'));
|
||||
}
|
||||
|
||||
if (options.js) {
|
||||
toJS(tree);
|
||||
}
|
||||
|
||||
if (!options.buildable) {
|
||||
tree.delete(join(options.projectRoot, 'package.json'));
|
||||
}
|
||||
|
||||
updateTsConfig(tree, options);
|
||||
}
|
||||
|
||||
async function addJest(
|
||||
tree: Tree,
|
||||
options: NormalizedSchema
|
||||
): Promise<GeneratorCallback> {
|
||||
const { jestProjectGenerator } = ensurePackage('@nrwl/jest', nxVersion);
|
||||
return await jestProjectGenerator(tree, {
|
||||
...options,
|
||||
project: options.name,
|
||||
setupFile: 'none',
|
||||
supportTsx: true,
|
||||
babelJest: options.babelJest,
|
||||
skipSerializers: true,
|
||||
testEnvironment: options.testEnvironment,
|
||||
skipFormat: true,
|
||||
});
|
||||
}
|
||||
|
||||
function addTypescript(tree: Tree, options: NormalizedSchema) {
|
||||
// add tsconfig.base.json
|
||||
if (!options.skipTsConfig && !getRootTsConfigFileName()) {
|
||||
generateFiles(tree, joinPathFragments(__dirname, './files/root'), '.', {});
|
||||
}
|
||||
|
||||
return !options.js
|
||||
? addDependenciesToPackageJson(tree, {}, { typescript: typescriptVersion })
|
||||
: () => {};
|
||||
}
|
||||
|
||||
export async function libraryGenerator(tree: Tree, schema: Schema) {
|
||||
const options = normalizeOptions(tree, schema);
|
||||
const tasks: GeneratorCallback[] = [];
|
||||
|
||||
addTypescript(tree, options);
|
||||
createFiles(tree, options);
|
||||
addProject(tree, options);
|
||||
|
||||
if (options.linter !== 'none') {
|
||||
const lintCallback = await addLint(tree, options);
|
||||
tasks.push(lintCallback);
|
||||
}
|
||||
if (options.unitTestRunner === 'jest') {
|
||||
const jestCallback = await addJest(tree, options);
|
||||
tasks.push(jestCallback);
|
||||
}
|
||||
if (!options.skipTsConfig) {
|
||||
updateRootTsConfig(tree, options);
|
||||
}
|
||||
|
||||
if (!options.skipFormat) {
|
||||
await formatFiles(tree);
|
||||
}
|
||||
|
||||
return runTasksInSerial(...tasks);
|
||||
}
|
||||
|
||||
export default libraryGenerator;
|
||||
export const librarySchematic = convertNxGenerator(libraryGenerator);
|
||||
|
||||
function normalizeOptions(tree: Tree, options: Schema): NormalizedSchema {
|
||||
const name = names(options.name).fileName;
|
||||
const { layoutDirectory, projectDirectory } = extractLayoutDirectory(
|
||||
options.directory ? `${names(options.directory).fileName}/${name}` : name
|
||||
);
|
||||
|
||||
if (!options.unitTestRunner) {
|
||||
options.unitTestRunner = 'jest';
|
||||
}
|
||||
|
||||
if (!options.linter) {
|
||||
const { Linter } = ensurePackage('@nrwl/linter', nxVersion);
|
||||
options.linter = Linter.EsLint;
|
||||
}
|
||||
|
||||
const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');
|
||||
const fileName = getCaseAwareFileName({
|
||||
fileName: options.simpleModuleName ? name : projectName,
|
||||
pascalCaseFiles: options.pascalCaseFiles,
|
||||
});
|
||||
|
||||
const { libsDir: defaultLibsDir, npmScope } = getWorkspaceLayout(tree);
|
||||
const libsDir = layoutDirectory ?? defaultLibsDir;
|
||||
|
||||
const projectRoot = joinPathFragments(libsDir, projectDirectory);
|
||||
|
||||
const parsedTags = options.tags
|
||||
? options.tags.split(',').map((s) => s.trim())
|
||||
: [];
|
||||
|
||||
const importPath =
|
||||
options.importPath || getImportPath(npmScope, projectDirectory);
|
||||
|
||||
return {
|
||||
...options,
|
||||
fileName,
|
||||
name: projectName,
|
||||
projectRoot,
|
||||
projectDirectory,
|
||||
parsedTags,
|
||||
importPath,
|
||||
libsDir,
|
||||
};
|
||||
}
|
||||
|
||||
function getCaseAwareFileName(options: {
|
||||
pascalCaseFiles: boolean;
|
||||
fileName: string;
|
||||
}) {
|
||||
const normalized = names(options.fileName);
|
||||
|
||||
return options.pascalCaseFiles ? normalized.className : normalized.fileName;
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
// nx-ignore-next-line
|
||||
const { Linter } = require('@nrwl/linter');
|
||||
|
||||
export interface Schema {
|
||||
name: string;
|
||||
directory?: string;
|
||||
skipTsConfig?: boolean;
|
||||
skipFormat?: boolean;
|
||||
tags?: string;
|
||||
simpleModuleName?: boolean;
|
||||
unitTestRunner?: 'jest' | 'none';
|
||||
linter?: Linter;
|
||||
testEnvironment?: 'jsdom' | 'node';
|
||||
importPath?: string;
|
||||
js?: boolean;
|
||||
babelJest?: boolean;
|
||||
pascalCaseFiles?: boolean;
|
||||
strict?: boolean;
|
||||
skipBabelrc?: boolean;
|
||||
buildable?: boolean;
|
||||
setParserOptionsProject?: boolean;
|
||||
standaloneConfig?: boolean;
|
||||
}
|
||||
@ -1,112 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/schema",
|
||||
"$id": "NxTypescriptLibrary",
|
||||
"cli": "nx",
|
||||
"title": "Create a TypeScript Library",
|
||||
"description": "Create a TypeScript Library.",
|
||||
"type": "object",
|
||||
"examples": [
|
||||
{
|
||||
"command": "nx g lib mylib --directory=myapp",
|
||||
"description": "Generate `libs/myapp/mylib`"
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "Library name.",
|
||||
"$default": {
|
||||
"$source": "argv",
|
||||
"index": 0
|
||||
},
|
||||
"x-prompt": "What name would you like to use for the library?",
|
||||
"pattern": "^[a-zA-Z].*$"
|
||||
},
|
||||
"directory": {
|
||||
"type": "string",
|
||||
"description": "A directory where the lib is placed.",
|
||||
"x-priority": "important"
|
||||
},
|
||||
"linter": {
|
||||
"description": "The tool to use for running lint checks.",
|
||||
"type": "string",
|
||||
"enum": ["eslint"],
|
||||
"default": "eslint"
|
||||
},
|
||||
"unitTestRunner": {
|
||||
"type": "string",
|
||||
"enum": ["jest", "none"],
|
||||
"description": "Test runner to use for unit tests.",
|
||||
"default": "jest"
|
||||
},
|
||||
"tags": {
|
||||
"type": "string",
|
||||
"description": "Add tags to the library (used for linting)."
|
||||
},
|
||||
"skipFormat": {
|
||||
"description": "Skip formatting files.",
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"x-priority": "internal"
|
||||
},
|
||||
"skipTsConfig": {
|
||||
"type": "boolean",
|
||||
"description": "Do not update `tsconfig.json` for development experience.",
|
||||
"default": false
|
||||
},
|
||||
"testEnvironment": {
|
||||
"type": "string",
|
||||
"enum": ["jsdom", "node"],
|
||||
"description": "The test environment to use if `unitTestRunner` is set to `jest`.",
|
||||
"default": "jsdom"
|
||||
},
|
||||
"importPath": {
|
||||
"type": "string",
|
||||
"description": "The library name used to import it, like `@myorg/my-awesome-lib`.",
|
||||
"x-priority": "important"
|
||||
},
|
||||
"babelJest": {
|
||||
"type": "boolean",
|
||||
"description": "Use `babel` instead `ts-jest`.",
|
||||
"default": false
|
||||
},
|
||||
"pascalCaseFiles": {
|
||||
"type": "boolean",
|
||||
"description": "Use pascal case file names.",
|
||||
"alias": "P",
|
||||
"default": false
|
||||
},
|
||||
"js": {
|
||||
"type": "boolean",
|
||||
"description": "Generate JavaScript files rather than TypeScript files.",
|
||||
"default": false
|
||||
},
|
||||
"strict": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to enable `tsconfig` strict mode or not.",
|
||||
"default": true
|
||||
},
|
||||
"skipBabelrc": {
|
||||
"type": "boolean",
|
||||
"description": "Do not generate `.babelrc` file. Useful for Node libraries that are not compiled by Babel.",
|
||||
"default": false
|
||||
},
|
||||
"buildable": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Generate a buildable library."
|
||||
},
|
||||
"setParserOptionsProject": {
|
||||
"type": "boolean",
|
||||
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
|
||||
"default": false
|
||||
},
|
||||
"standaloneConfig": {
|
||||
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"x-deprecated": "Nx only supports standaloneConfig"
|
||||
}
|
||||
},
|
||||
"required": ["name"]
|
||||
}
|
||||
@ -6,7 +6,9 @@ import {
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { Schema } from '../schema';
|
||||
import { checkDestination } from './check-destination';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('checkDestination', () => {
|
||||
let tree: Tree;
|
||||
@ -36,7 +38,6 @@ describe('checkDestination', () => {
|
||||
it('should throw an error if the path already exists', async () => {
|
||||
await libraryGenerator(tree, {
|
||||
name: 'my-other-lib',
|
||||
standaloneConfig: false,
|
||||
});
|
||||
|
||||
const schema: Schema = {
|
||||
|
||||
@ -4,17 +4,19 @@ import {
|
||||
Tree,
|
||||
} from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
import { NormalizedSchema } from '../schema';
|
||||
import { moveProjectFiles } from './move-project-files';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('moveProject', () => {
|
||||
let tree: Tree;
|
||||
let projectConfig: ProjectConfiguration;
|
||||
|
||||
beforeEach(async () => {
|
||||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
||||
await libraryGenerator(tree, { name: 'my-lib', standaloneConfig: false });
|
||||
await libraryGenerator(tree, { name: 'my-lib' });
|
||||
projectConfig = readProjectConfiguration(tree, 'my-lib');
|
||||
});
|
||||
|
||||
|
||||
@ -6,10 +6,12 @@ import {
|
||||
writeJson,
|
||||
} from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
import { NormalizedSchema } from '../schema';
|
||||
import { updateCypressConfig } from './update-cypress-config';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('updateCypressConfig', () => {
|
||||
let tree: Tree;
|
||||
let schema: NormalizedSchema;
|
||||
|
||||
@ -6,10 +6,12 @@ import {
|
||||
} from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { Linter } from '../../../utils/lint';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
import { NormalizedSchema } from '../schema';
|
||||
import { updateEslintrcJson } from './update-eslintrc-json';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('updateEslint', () => {
|
||||
let tree: Tree;
|
||||
let schema: NormalizedSchema;
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { readJson, readProjectConfiguration, Tree } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
import { Schema } from '../schema';
|
||||
import { updateImports } from './update-imports';
|
||||
import { normalizeSchema } from './normalize-schema';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('updateImports', () => {
|
||||
let tree: Tree;
|
||||
let schema: Schema;
|
||||
@ -25,6 +27,7 @@ describe('updateImports', () => {
|
||||
// source and destination to make sure that the workspace has libraries with those names.
|
||||
await libraryGenerator(tree, {
|
||||
name: 'my-destination',
|
||||
config: 'project',
|
||||
});
|
||||
await libraryGenerator(tree, {
|
||||
name: 'my-source',
|
||||
@ -247,7 +250,7 @@ describe('updateImports', () => {
|
||||
tree.write(
|
||||
importerFilePath,
|
||||
`import { MyClass } from '@proj/my-source';
|
||||
|
||||
|
||||
export MyExtendedClass extends MyClass {};`
|
||||
);
|
||||
schema.updateImportPath = false;
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { readProjectConfiguration, Tree } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
import { NormalizedSchema } from '../schema';
|
||||
import { updateJestConfig } from './update-jest-config';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('updateJestConfig', () => {
|
||||
let tree: Tree;
|
||||
|
||||
@ -148,7 +150,7 @@ describe('updateJestConfig', () => {
|
||||
tree.write(
|
||||
rootJestConfigPath,
|
||||
`const { getJestProjects } = require('@nrwl/jest');
|
||||
|
||||
|
||||
module.exports = {
|
||||
projects: [...getJestProjects(), '<rootDir>/libs/some/test/dir/my-source']
|
||||
};
|
||||
@ -187,7 +189,7 @@ module.exports = {
|
||||
tree.write(
|
||||
rootJestConfigPath,
|
||||
`const { getJestProjects } = require('@nrwl/jest');
|
||||
|
||||
|
||||
module.exports = {
|
||||
projects: [...getJestProjects(), '<rootDir>/libs/some/test/dir/my-source', '<rootDir>/libs/foo']
|
||||
};
|
||||
|
||||
@ -22,7 +22,11 @@ export function updateJestConfig(
|
||||
if (tree.exists(jestConfigPath)) {
|
||||
const oldContent = tree.read(jestConfigPath, 'utf-8');
|
||||
|
||||
const findName = new RegExp(`'${schema.projectName}'`, 'g');
|
||||
// ensure both single and double quotes are replaced
|
||||
const findName = new RegExp(
|
||||
`'${schema.projectName}'|"${schema.projectName}"|\`${schema.projectName}\``,
|
||||
'g'
|
||||
);
|
||||
const findDir = new RegExp(project.root, 'g');
|
||||
|
||||
const newContent = oldContent
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { readJson, Tree, writeJson } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
import { NormalizedSchema } from '../schema';
|
||||
import { updatePackageJson } from './update-package-json';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('updatePackageJson', () => {
|
||||
let tree: Tree;
|
||||
let schema: NormalizedSchema;
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { readProjectConfiguration, Tree } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
import { NormalizedSchema } from '../schema';
|
||||
import { updateProjectRootFiles } from './update-project-root-files';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('updateProjectRootFiles', () => {
|
||||
let tree: Tree;
|
||||
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { Tree } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { join } from 'path';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
import { NormalizedSchema } from '../schema';
|
||||
import { updateReadme } from './update-readme';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('updateReadme', () => {
|
||||
let tree: Tree;
|
||||
let schema: NormalizedSchema;
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { readProjectConfiguration, Tree } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
import { NormalizedSchema } from '../schema';
|
||||
import { updateStorybookConfig } from './update-storybook-config';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('updateStorybookConfig', () => {
|
||||
let tree: Tree;
|
||||
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import { readJson, Tree } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { moveGenerator } from './move';
|
||||
import { libraryGenerator } from '../library/library';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('move', () => {
|
||||
let tree: Tree;
|
||||
|
||||
@ -8,7 +8,7 @@ import {
|
||||
import { Schema } from '../schema';
|
||||
import { checkDependencies } from './check-dependencies';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
// import { libraryGenerator } from '../../library/library';
|
||||
// let projectGraph: ProjectGraph;
|
||||
// jest.mock('../../../core/project-graph', () => ({
|
||||
// ...jest.requireActual<any>('../../../core/project-graph'),
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { readProjectConfiguration, Tree } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { Schema } from '../schema';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
import { removeProject } from '@nrwl/workspace/src/generators/remove/lib/remove-project';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('moveProject', () => {
|
||||
let schema: Schema;
|
||||
let tree: Tree;
|
||||
|
||||
@ -6,7 +6,9 @@ import { join } from 'path';
|
||||
|
||||
import { Schema } from '../schema';
|
||||
import { updateJestConfig } from './update-jest-config';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('updateRootJestConfig', () => {
|
||||
let tree: Tree;
|
||||
|
||||
@ -7,7 +7,9 @@ import {
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { Schema } from '../schema';
|
||||
import { updateTsconfig } from './update-tsconfig';
|
||||
import { libraryGenerator } from '../../library/library';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
let graph: ProjectGraph;
|
||||
jest.mock('@nrwl/devkit', () => {
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import runCommands from './run-commands';
|
||||
import { libraryGenerator } from '../library/library';
|
||||
import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration';
|
||||
|
||||
// nx-ignore-next-line
|
||||
const { libraryGenerator } = require('@nrwl/js');
|
||||
|
||||
describe('run-commands', () => {
|
||||
it('should generate a target', async () => {
|
||||
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Tree, formatFiles, installPackagesTask } from '@nrwl/devkit';
|
||||
import { libraryGenerator } from '@nrwl/workspace/generators';
|
||||
import { libraryGenerator } from '@nrwl/js';
|
||||
|
||||
export default async function(tree: Tree, schema: any) {
|
||||
await libraryGenerator(tree, {name: schema.name});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user