Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): remove @nrwl/workspace:lib #16122

Merged
merged 8 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -6705,14 +6705,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",
Expand Down
9 changes: 0 additions & 9 deletions docs/generated/manifests/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3030,15 +3030,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",
Expand Down
9 changes: 0 additions & 9 deletions docs/generated/packages-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2996,15 +2996,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",
Expand Down
5 changes: 2 additions & 3 deletions docs/generated/packages/web/documents/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
1 change: 0 additions & 1 deletion docs/shared/deprecated/default-collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
5 changes: 2 additions & 3 deletions docs/shared/packages/web/web-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/recipes/generators/composing-generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/recipes/generators/creating-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/recipes/generators/generator-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ''}` });
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/recipes/generators/local-generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
16 changes: 5 additions & 11 deletions e2e/jest/src/jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import {
runCLI,
runCLIAsync,
uniq,
readJson,
updateFile,
expectJestTestsToPass,
cleanupProject,
readFile,
checkFilesExist,
} from '@nrwl/e2e/utils';

describe('Jest', () => {
Expand All @@ -20,18 +17,15 @@ describe('Jest', () => {
afterAll(() => cleanupProject());

it('should be able test projects using jest', async () => {
await expectJestTestsToPass('@nrwl/workspace:lib');
await expectJestTestsToPass('@nrwl/js:lib');
}, 500000);

it('should merge with jest config globals', async () => {
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`
Expand Down Expand Up @@ -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');
});
`
);
Expand All @@ -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`,
Expand Down
75 changes: 71 additions & 4 deletions e2e/js/src/js.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
checkFilesDoNotExist,
checkFilesExist,
cleanupProject,
createFile,
expectJestTestsToPass,
newProject,
readJson,
runCLI,
runCLIAsync,
uniq,
updateFile,
updateJson,
Expand Down Expand Up @@ -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`);
});
});
20 changes: 9 additions & 11 deletions e2e/linter/src/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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[
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`);
Expand Down Expand Up @@ -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`);
Expand Down Expand Up @@ -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`);
Expand Down
8 changes: 4 additions & 4 deletions e2e/nx-init/src/nx-project-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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: '',
Expand All @@ -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: '',
Expand Down
4 changes: 2 additions & 2 deletions e2e/nx-misc/src/extras.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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}`
Expand Down
6 changes: 3 additions & 3 deletions e2e/nx-misc/src/watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading