feat(repo): add exports to package.json of package (#20090)
This commit is contained in:
parent
b3423679c0
commit
7416b9c4a7
@ -1,5 +1,59 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`create-nodes-plugin/generator generator should add the plugin path to package.json exports 1`] = `
|
||||||
|
"{
|
||||||
|
"name": "@nx/eslint",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": false,
|
||||||
|
"description": "Some description",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/nrwl/nx.git",
|
||||||
|
"directory": "packages/eslint"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"Monorepo",
|
||||||
|
"eslint",
|
||||||
|
"Web",
|
||||||
|
"CLI"
|
||||||
|
],
|
||||||
|
"main": "./index",
|
||||||
|
"typings": "./index.d.ts",
|
||||||
|
"author": "Victor Savkin",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/nrwl/nx/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://nx.dev",
|
||||||
|
"generators": "./generators.json",
|
||||||
|
"executors": "./executors.json",
|
||||||
|
"ng-update": {
|
||||||
|
"requirements": {},
|
||||||
|
"migrations": "./migrations.json"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@nx/devkit": "file:../devkit"
|
||||||
|
},
|
||||||
|
"peerDependencies": {},
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"exports": {
|
||||||
|
".": "./index.js",
|
||||||
|
"./package.json": "./package.json",
|
||||||
|
"./migrations.json": "./migrations.json",
|
||||||
|
"./generators.json": "./generators.json",
|
||||||
|
"./executors.json": "./executors.json",
|
||||||
|
"./executors": "./executors.js",
|
||||||
|
"./src/executors/*/schema.json": "./src/executors/*/schema.json",
|
||||||
|
"./src/executors/*.impl": "./src/executors/*.impl.js",
|
||||||
|
"./src/executors/*/compat": "./src/executors/*/compat.js",
|
||||||
|
"./plugin": "./plugin.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`create-nodes-plugin/generator generator should run successfully 1`] = `
|
exports[`create-nodes-plugin/generator generator should run successfully 1`] = `
|
||||||
"import {
|
"import {
|
||||||
CreateNodes,
|
CreateNodes,
|
||||||
|
|||||||
@ -17,14 +17,13 @@ describe('create-nodes-plugin/generator generator', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
writeJson(tree, 'packages/eslint/package.json', {});
|
|
||||||
|
|
||||||
jest.spyOn(process, 'cwd').mockReturnValue('/virtual/packages/eslint');
|
jest.spyOn(process, 'cwd').mockReturnValue('/virtual/packages/eslint');
|
||||||
|
|
||||||
setCwd('packages/eslint');
|
setCwd('packages/eslint');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run successfully', async () => {
|
it('should run successfully', async () => {
|
||||||
|
writeJson(tree, 'packages/eslint/package.json', {});
|
||||||
await generatorGenerator(tree);
|
await generatorGenerator(tree);
|
||||||
expect(
|
expect(
|
||||||
tree.read('packages/eslint/src/plugins/plugin.ts').toString()
|
tree.read('packages/eslint/src/plugins/plugin.ts').toString()
|
||||||
@ -40,4 +39,55 @@ describe('create-nodes-plugin/generator generator', () => {
|
|||||||
.toString()
|
.toString()
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should add the plugin path to package.json exports', async () => {
|
||||||
|
writeJson(tree, 'packages/eslint/package.json', {
|
||||||
|
name: '@nx/eslint',
|
||||||
|
version: '0.0.1',
|
||||||
|
private: false,
|
||||||
|
description: 'Some description',
|
||||||
|
repository: {
|
||||||
|
type: 'git',
|
||||||
|
url: 'https://github.com/nrwl/nx.git',
|
||||||
|
directory: 'packages/eslint',
|
||||||
|
},
|
||||||
|
keywords: ['Monorepo', 'eslint', 'Web', 'CLI'],
|
||||||
|
main: './index',
|
||||||
|
typings: './index.d.ts',
|
||||||
|
author: 'Victor Savkin',
|
||||||
|
license: 'MIT',
|
||||||
|
bugs: {
|
||||||
|
url: 'https://github.com/nrwl/nx/issues',
|
||||||
|
},
|
||||||
|
homepage: 'https://nx.dev',
|
||||||
|
generators: './generators.json',
|
||||||
|
executors: './executors.json',
|
||||||
|
'ng-update': {
|
||||||
|
requirements: {},
|
||||||
|
migrations: './migrations.json',
|
||||||
|
},
|
||||||
|
dependencies: {
|
||||||
|
'@nx/devkit': 'file:../devkit',
|
||||||
|
},
|
||||||
|
peerDependencies: {},
|
||||||
|
publishConfig: {
|
||||||
|
access: 'public',
|
||||||
|
},
|
||||||
|
exports: {
|
||||||
|
'.': './index.js',
|
||||||
|
'./package.json': './package.json',
|
||||||
|
'./migrations.json': './migrations.json',
|
||||||
|
'./generators.json': './generators.json',
|
||||||
|
'./executors.json': './executors.json',
|
||||||
|
'./executors': './executors.js',
|
||||||
|
'./src/executors/*/schema.json': './src/executors/*/schema.json',
|
||||||
|
'./src/executors/*.impl': './src/executors/*.impl.js',
|
||||||
|
'./src/executors/*/compat': './src/executors/*/compat.js',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await generatorGenerator(tree);
|
||||||
|
expect(
|
||||||
|
tree.read('packages/eslint/package.json', 'utf-8')
|
||||||
|
).toMatchSnapshot();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,4 +1,11 @@
|
|||||||
import { formatFiles, generateFiles, names, Tree } from '@nx/devkit';
|
import {
|
||||||
|
formatFiles,
|
||||||
|
generateFiles,
|
||||||
|
joinPathFragments,
|
||||||
|
names,
|
||||||
|
Tree,
|
||||||
|
updateJson,
|
||||||
|
} from '@nx/devkit';
|
||||||
import { basename, join, relative } from 'path';
|
import { basename, join, relative } from 'path';
|
||||||
import migrationGenerator from '@nx/plugin/src/generators/migration/migration';
|
import migrationGenerator from '@nx/plugin/src/generators/migration/migration';
|
||||||
|
|
||||||
@ -21,6 +28,17 @@ export async function generatorGenerator(tree: Tree) {
|
|||||||
propertyName,
|
propertyName,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
updateJson(
|
||||||
|
tree,
|
||||||
|
joinPathFragments(relative(tree.root, cwd), 'package.json'),
|
||||||
|
(json) => {
|
||||||
|
if (json['exports']) {
|
||||||
|
json['exports']['./plugin'] = './plugin.js';
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
await formatFiles(tree);
|
await formatFiles(tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user