Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -977,95 +977,40 @@ describe('migrate-converged-pkg generator', () => {
});
});

describe(`npm config setup`, () => {
it(`should update .npmignore config`, async () => {
function getNpmIgnoreConfig(projectConfig: ReadProjectConfiguration) {
return tree.read(`${projectConfig.root}/.npmignore`)?.toString('utf-8');
}
describe(`npm publish setup`, () => {
it(`should replace .npmignore config with package.json#files`, async () => {
const getNpmIgnoreConfigPath = (projectConfig: ReadProjectConfiguration) => `${projectConfig.root}/.npmignore`;

const projectConfig = readProjectConfiguration(tree, options.name);
let npmIgnoreConfig = getNpmIgnoreConfig(projectConfig);

expect(npmIgnoreConfig).toMatchInlineSnapshot(`
"*.api.json
*.config.js
*.log
*.nuspec
*.test.*
*.yml
.editorconfig
.eslintrc*
.eslintcache
.gitattributes
.gitignore
.vscode
coverage
dist/storybook
dist/*.stats.html
dist/*.stats.json
dist/demo
fabric-test*
gulpfile.js
images
index.html
jsconfig.json
node_modules
results
src/**/*
!src/**/examples/*.tsx
!src/**/docs/**/*.md
!src/**/*.types.ts
temp
tsconfig.json
tsd.json
tslint.json
typings
visualtests"
const npmIgnoreConfigPath = getNpmIgnoreConfigPath(projectConfig);

expect(tree.exists(npmIgnoreConfigPath)).toBe(true);

await generator(tree, options);

expect(tree.exists(npmIgnoreConfigPath)).toBe(false);
let pkgJson = readJson<PackageJson>(tree, `${projectConfig.root}/package.json`);

expect(pkgJson.files).toMatchInlineSnapshot(`
Array [
"lib",
"lib-commonjs",
"dist/*.d.ts",
]
`);

updateProjectConfiguration(tree, projectConfig.name!, { ...projectConfig, tags: ['ships-amd'] });
await generator(tree, options);

npmIgnoreConfig = getNpmIgnoreConfig(projectConfig);

expect(npmIgnoreConfig).toMatchInlineSnapshot(`
".storybook/
.vscode/
bundle-size/
config/
coverage/
docs/
etc/
node_modules/
src/
stories/
dist/types/
temp/
__fixtures__
__mocks__
__tests__

*.api.json
*.log
*.spec.*
*.cy.*
*.test.*
*.yml

# config files
*config.*
*rc.*
.editorconfig
.eslint*
.git*
.prettierignore
.swcrc
project.json

# exclude gitignore patterns explicitly
!lib
!lib-commonjs
!lib-amd
!dist/*.d.ts
"
pkgJson = readJson<PackageJson>(tree, `${projectConfig.root}/package.json`);

expect(pkgJson.files).toMatchInlineSnapshot(`
Array [
"lib",
"lib-commonjs",
"lib-amd",
"dist/*.d.ts",
]
`);
});
});
Expand Down Expand Up @@ -1606,42 +1551,7 @@ function setupDummyPackage(
jestSetupFile: stripIndents`
/** Jest test setup file. */
`,
npmConfig: stripIndents`
*.api.json
*.config.js
*.log
*.nuspec
*.test.*
*.yml
.editorconfig
.eslintrc*
.eslintcache
.gitattributes
.gitignore
.vscode
coverage
dist/storybook
dist/*.stats.html
dist/*.stats.json
dist/demo
fabric-test*
gulpfile.js
images
index.html
jsconfig.json
node_modules
results
src/**/*
!src/**/examples/*.tsx
!src/**/docs/**/*.md
!src/**/*.types.ts
temp
tsconfig.json
tsd.json
tslint.json
typings
visualtests
`,
npmConfig: stripIndents``,
babelConfig: {
...normalizedOptions.babelConfig,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ function runMigrationOnProject(tree: Tree, schema: AssertedSchema, _userLog: Use

setupCypress(tree, options);

setupNpmIgnoreConfig(tree, options);
setupBabel(tree, options);

updateNxProject(tree, options);
Expand Down Expand Up @@ -594,12 +593,6 @@ function updateNxProject(tree: Tree, options: NormalizedSchema) {
return tree;
}

function setupNpmIgnoreConfig(tree: Tree, options: NormalizedSchema) {
tree.write(options.paths.npmConfig, templates.npmIgnoreConfig);

return tree;
}

function setupSwcConfig(tree: Tree, options: NormalizedSchema) {
const swcConfig = templates.swcConfig();
writeJson(tree, joinPathFragments(options.projectConfig.root, '.swcrc'), swcConfig);
Expand Down Expand Up @@ -693,6 +686,7 @@ function updatePackageJson(tree: Tree, options: NormalizedSchemaWithTsConfigs) {
packageJson = setupScripts(packageJson);
packageJson = setupExportMaps(packageJson);
packageJson = addSwcHelpers(packageJson);
packageJson = setupNpmPublishFiles(packageJson);

writeJson(tree, options.paths.packageJson, packageJson);

Expand Down Expand Up @@ -739,13 +733,27 @@ function updatePackageJson(tree: Tree, options: NormalizedSchemaWithTsConfigs) {
return './' + path.posix.normalize(entryPath);
}
}
}

//TODO: remove after migration to swc transpilation is complete
function addSwcHelpers(json: PackageJson) {
delete json.dependencies?.tslib;
json.dependencies = { ...json.dependencies, '@swc/helpers': '^0.4.14' };
return json;
//TODO: remove after migration to swc transpilation is complete
function addSwcHelpers(json: PackageJson) {
delete json.dependencies?.tslib;
json.dependencies = { ...json.dependencies, '@swc/helpers': '^0.5.1' };
return json;
}

function setupNpmPublishFiles(json: PackageJson) {
json.files = json.files ?? [];
json.files = [
'lib',
'lib-commonjs',
options.projectConfig.tags?.includes('ships-amd') ? 'lib-amd' : '',
'dist/*.d.ts',
].filter(Boolean);

tree.delete(options.paths.npmConfig);

return json;
}
}

function updateApiExtractor(tree: Tree, options: NormalizedSchemaWithTsConfigs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {
logger,
readNxJson,
NxJsonConfiguration,
readJson,
} from '@nx/devkit';
import type { Linter } from 'eslint';

import type { TsConfig } from '../../types';
import type { PackageJson, TsConfig } from '../../types';
import generator from './index';
import { MigrateV8PkgGeneratorSchema } from './schema';

Expand Down Expand Up @@ -65,50 +66,24 @@ describe('migrate-v8-pkg generator', () => {
});

describe(`--name`, () => {
it(`should setup .npmignore`, async () => {
await generator(tree, options);
describe(`npm publish setup`, () => {
it(`should replace .npmignore config with package.json#files`, async () => {
expect(tree.exists(`packages/eight/.npmignore`)).toBe(true);

expect(tree.read(`packages/eight/.npmignore`, 'utf-8')).toMatchInlineSnapshot(`
"*.api.json
*.config.js
*.log
*.nuspec
*.test.*
*.yml
.editorconfig
.eslintrc*
.eslintcache
.gitattributes
.gitignore
.vscode
coverage
dist/storybook
dist/*.stats.html
dist/*.stats.json
dist/demo
fabric-test*
gulpfile.js
images
index.html
jsconfig.json
node_modules
results
src/**/*
!src/**/*.types.ts
temp
tsconfig.json
tsd.json
tslint.json
typings
visualtests
project.json
await generator(tree, options);

# exclude gitignore patterns explicitly
!lib
!lib-commonjs
!lib-amd
!dist"
`);
expect(tree.exists(`packages/eight/.npmignore`)).toBe(false);

const pkgJson = readJson<PackageJson>(tree, `packages/eight/package.json`);
expect(pkgJson.files).toMatchInlineSnapshot(`
Array [
"lib",
"lib-commonjs",
"lib-amd",
"dist",
]
`);
});
});
});

Expand Down Expand Up @@ -244,40 +219,7 @@ function setupDummyPackage(
// Configure enzyme.
configure({ adapter: new Adapter() });
`,
npmConfig: stripIndents`
*.api.json
*.config.js
*.log
*.nuspec
*.test.*
*.yml
.editorconfig
.eslintrc*
.eslintcache
.gitattributes
.gitignore
.vscode
coverage
dist/storybook
dist/*.stats.html
dist/*.stats.json
dist/demo
fabric-test*
gulpfile.js
images
index.html
jsconfig.json
node_modules
results
src/**/*
!src/**/*.types.ts
temp
tsconfig.json
tsd.json
tslint.json
typings
visualtests
`,
npmConfig: stripIndents``,
};

if (typeof normalizedOptions.eslintConfig === 'string') {
Expand Down
Loading