Skip to content

Commit e5b213e

Browse files
layershifterclaude
andcommitted
fix(e2e): update packLocalPackage for new dist layout
- Add rollup.config.cjs to style-types (consistent with core/react/shadow-dom) - Update style-types exports to use index.esm.js/index.cjs.js pattern - Fix packLocalPackage to copy package.json into dist with rewritten paths Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4a13063 commit e5b213e

4 files changed

Lines changed: 40 additions & 7 deletions

File tree

e2e/utils/src/packLocalPackage.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,37 @@ import * as logSymbols from 'log-symbols';
44

55
import { sh } from './sh';
66

7+
/**
8+
* Rewrites paths in package.json to be relative to the dist directory.
9+
* e.g. "./dist/index.esm.js" becomes "./index.esm.js"
10+
*/
11+
function rewritePackageJsonForDist(packageJsonContent: string): string {
12+
return packageJsonContent.replace(/"\.\/(dist)\//g, '"./');
13+
}
14+
715
export async function packLocalPackage(rootDir: string, tempDir: string, packageName: string) {
8-
const packagePath = path.resolve(rootDir, 'packages', packageName.split('/')[1], 'dist');
9-
const packagePathExists = !!(await fs.promises.stat(packagePath).catch(() => false));
16+
const packagePath = path.resolve(rootDir, 'packages', packageName.split('/')[1]);
17+
const distPath = path.resolve(packagePath, 'dist');
18+
const distPathExists = !!(await fs.promises.stat(distPath).catch(() => false));
1019

11-
if (!packagePathExists) {
12-
throw new Error(`A directory with artifacts (${packagePath}) does not exist`);
20+
if (!distPathExists) {
21+
throw new Error(`A directory with artifacts (${distPath}) does not exist`);
1322
}
1423

24+
// Copy package.json into dist with paths rewritten to be relative to dist.
25+
// The old @nx/rollup:rollup executor did this automatically; with plain rollup we do it manually.
26+
const packageJsonContent = await fs.promises.readFile(path.resolve(packagePath, 'package.json'), 'utf-8');
27+
await fs.promises.writeFile(path.resolve(distPath, 'package.json'), rewritePackageJsonForDist(packageJsonContent));
28+
1529
// Use `npm pack` because `yarn pack` incorrectly calculates the included files when the
1630
// files to include/exclude are specified by .npmignore rather than package.json `files`.
1731
// (--quiet outputs only the .tgz filename, not all the included files)
18-
const packFile = (await sh(`npm pack --quiet ${packagePath}`, tempDir, true)).trim();
32+
const packFile = (await sh(`npm pack --quiet ${distPath}`, tempDir, true)).trim();
1933
console.log(logSymbols.success, `Package "${packageName}" was packed`);
2034

35+
// Clean up the temporary package.json in dist
36+
await fs.promises.unlink(path.resolve(distPath, 'package.json'));
37+
2138
return {
2239
packageName,
2340
file: packFile,

packages/style-types/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
".": {
1717
"@griffel/source": "./src/index.ts",
1818
"types": "./dist/index.d.ts",
19-
"import": "./dist/index.js"
19+
"import": "./dist/index.esm.js",
20+
"require": "./dist/index.cjs.js",
21+
"default": "./dist/index.esm.js"
2022
}
2123
},
2224
"types": "./dist/index.d.ts",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { withNx } = require('@nx/rollup/with-nx');
2+
const getRollupOptions = require('../../tools/getRollupOptions');
3+
4+
module.exports = getRollupOptions(
5+
withNx({
6+
main: './src/index.ts',
7+
outputPath: './dist',
8+
tsConfig: './tsconfig.lib.json',
9+
compiler: 'babel',
10+
format: ['esm', 'cjs'],
11+
external: ['tslib'],
12+
sourceMap: true,
13+
}),
14+
);

packages/webpack-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"./package.json": "./package.json"
2424
},
2525
"dependencies": {
26-
"@griffel/transform": "^1.2.0",
2726
"@griffel/core": "^1.20.0",
27+
"@griffel/transform": "^1.2.0",
2828
"enhanced-resolve": "^5.15.0",
2929
"oxc-resolver": "^11.19.1",
3030
"stylis": "^4.2.0"

0 commit comments

Comments
 (0)