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
2 changes: 1 addition & 1 deletion tools/workspace-plugin/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@
"command": "node ./tools/workspace-plugin/scripts/check-dep-graph.js"
}
},
"tags": ["platform:any", "tools"]
"tags": ["platform:node", "tools"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('migrate-converged-pkg generator', () => {
const tsConfigTest = getTsConfig.test();

expect(tsConfigMain).toEqual({
extends: '../../../../../tsconfig.base.json',
extends: '../../tsconfig.base.json',
compilerOptions: {
importHelpers: true,
isolatedModules: true,
Expand Down Expand Up @@ -439,7 +439,7 @@ describe('migrate-converged-pkg generator', () => {
*/
module.exports = {
displayName: 'react-dummy',
preset: '../../../../../jest.preset.js',
preset: '../../jest.preset.js',
transform: {
'^.+\\\\\\\\.tsx?$': [
'ts-jest',
Expand Down Expand Up @@ -585,10 +585,10 @@ describe('migrate-converged-pkg generator', () => {
);

expect(tree.read(`${projectStorybookConfigPath}/main.js`)?.toString('utf-8')).toMatchInlineSnapshot(`
"const rootMain = require('../../../../../../.storybook/main');
"const rootMain = require('../../../.storybook/main');

module.exports =
/** @type {Omit<import('../../../../../../.storybook/main'), 'typescript'|'babel'>} */ ({
/** @type {Omit<import('../../../.storybook/main'), 'typescript'|'babel'>} */ ({
...rootMain,
stories: [
...rootMain.stories,
Expand All @@ -608,7 +608,7 @@ describe('migrate-converged-pkg generator', () => {
`);

expect(tree.read(`${projectStorybookConfigPath}/preview.js`)?.toString('utf-8')).toMatchInlineSnapshot(`
"import * as rootPreview from '../../../../../../.storybook/preview';
"import * as rootPreview from '../../../.storybook/preview';

/** @type {typeof rootPreview.decorators} */
export const decorators = [...rootPreview.decorators];
Expand Down Expand Up @@ -863,6 +863,7 @@ describe('migrate-converged-pkg generator', () => {

it(`should update package npm scripts`, async () => {
const projectConfig = readProjectConfiguration(tree, options.name);

const pkgJsonPath = `${projectConfig.root}/package.json`;
updateJson(tree, pkgJsonPath, json => {
json.scripts.docs = 'api-extractor run --config=config/api-extractor.local.json --local';
Expand Down Expand Up @@ -901,31 +902,30 @@ describe('migrate-converged-pkg generator', () => {
just: 'just-scripts',
lint: 'just-scripts lint',
test: 'jest --passWithNoTests',
'test-ssr': 'test-ssr "./stories/**/*.stories.tsx"',
'type-check': 'tsc -b tsconfig.json',
});
});

describe(`export-maps`, () => {
function setup(config: { name: string; addModuleField?: boolean }) {
const addModuleField = config.addModuleField ?? true;
const projectConfig = readProjectConfiguration(tree, config.name);
const pkgJsonPath = `${projectConfig.root}/package.json`;
// verify test-ssr addition
updateProjectConfiguration(tree, options.name, { ...projectConfig, tags: ['platform:web'] });
tree.write(joinPathFragments(projectConfig.root, 'stories/Foo/Foo.stories.tsx'), 'export {}');

if (addModuleField) {
updateJson(tree, pkgJsonPath, json => {
json.module = './lib/index.js';
return json;
});
}
await generator(tree, options);

const getPackageJson = () => readJson(tree, pkgJsonPath);
pkgJson = readJson(tree, `${projectConfig.root}/package.json`);

return { getPackageJson };
}
expect(pkgJson.scripts).toEqual(
expect.objectContaining({
'test-ssr': 'test-ssr "./stories/**/*.stories.tsx"',
}),
);
});

describe(`export-maps`, () => {
it(`should update exports map`, async () => {
const { getPackageJson } = setup({ name: options.name });
const { getPackageJson } = updatePackageJson(tree, {
projectName: options.name,
jsonUpdates: { module: './lib/index.js', style: './css/index.css' },
});

let pkgJson = getPackageJson();

Expand All @@ -936,25 +936,28 @@ describe('migrate-converged-pkg generator', () => {
pkgJson = getPackageJson();

expect(pkgJson.exports).toMatchInlineSnapshot(`
Object {
".": Object {
"import": "./lib/index.js",
"node": "./lib-commonjs/index.js",
"require": "./lib-commonjs/index.js",
"types": "./dist/index.d.ts",
},
"./package.json": "./package.json",
}
`);
Object {
".": Object {
"import": "./lib/index.js",
"node": "./lib-commonjs/index.js",
"require": "./lib-commonjs/index.js",
"style": "./css/index.css",
"types": "./dist/index.d.ts",
},
"./package.json": "./package.json",
}
`);
});

it(`should update exports map based on main,module fields`, async () => {
const { getPackageJson } = setup({ name: options.name, addModuleField: false });
const { getPackageJson } = updatePackageJson(tree, {
projectName: options.name,
});

await generator(tree, options);

const pkgJson = getPackageJson();
expect(pkgJson.exports['.'].module).toBe(undefined);
Comment thread
Hotell marked this conversation as resolved.
expect((pkgJson.exports?.['.'] as { import?: string }).import).toBe(undefined);
});
});

Expand Down Expand Up @@ -989,27 +992,63 @@ describe('migrate-converged-pkg generator', () => {
await generator(tree, options);

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

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

it(`should set package.json#files bases on project setup`, async () => {
const projectConfig = readProjectConfiguration(tree, options.name);
updateProjectConfiguration(tree, projectConfig.name!, { ...projectConfig, tags: ['ships-amd'] });
await generator(tree, options);
let getPackageJson = updatePackageJson(tree, {
projectName: options.name,
jsonUpdates: { module: './lib/index.js', style: './sass/index.scss', bin: './bin/cli.js', storybook: {} },
}).getPackageJson;

pkgJson = readJson<PackageJson>(tree, `${projectConfig.root}/package.json`);
await generator(tree, options);

expect(pkgJson.files).toMatchInlineSnapshot(`
expect(getPackageJson().files).toMatchInlineSnapshot(`
Array [
"*.md",
"bin",
"dist/*.d.ts",
"lib",
"lib-commonjs",
"lib-amd",
"lib-commonjs",
"preset.js",
"sass",
]
`);

getPackageJson = updatePackageJson(tree, {
projectName: options.name,
jsonUpdates: {
module: './lib/index.js',
types: 'one/two/index.d.ts',
bin: { one: './bin/one.js', two: './bin-two/one.js' },
},
}).getPackageJson;

await generator(tree, options);

expect(getPackageJson().files).toMatchInlineSnapshot(`
Array [
"*.md",
"bin",
"bin-two",
"dist/*.d.ts",
"lib",
"lib-amd",
"lib-commonjs",
"one/two/*.d.ts",
"preset.js",
"sass",
]
`);
});
Expand Down Expand Up @@ -1268,6 +1307,27 @@ describe('migrate-converged-pkg generator', () => {
}
"
`);

// make sure it is added only once

await generator(tree, options);

expect(stripIndents`${tree.read(conformanceSetupPath, 'utf-8')}`).toEqual(
expect.stringContaining(stripIndents`
const defaultOptions: Partial<IsConformantOptions<TProps>> = {
tsConfig: { configName: 'tsconfig.spec.json' },
componentPath: require.main?.filename.replace('.test', ''),
extraTests: griffelTests as TestObject<TProps>,
testOptions: {
'make-styles-overrides-win': {
callCount: 2,
},
// TODO: https://github.com/microsoft/fluentui/issues/19618
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
};
`),
);
});
});

Expand Down Expand Up @@ -1654,3 +1714,17 @@ function assertAndReadNxJson(tree: Tree) {

return nxJson;
}

function updatePackageJson(tree: Tree, config: { projectName: string; jsonUpdates?: Partial<PackageJson> }) {
const projectConfig = readProjectConfiguration(tree, config.projectName);
const pkgJsonPath = `${projectConfig.root}/package.json`;

updateJson(tree, pkgJsonPath, json => {
Object.assign(json, config.jsonUpdates);
return json;
});

const getPackageJson = () => readJson<PackageJson>(tree, pkgJsonPath);

return { getPackageJson };
}
Loading