Skip to content

Commit 66e9762

Browse files
layershifterclaude
andcommitted
fix: update exports, fix rollup/tsc declaration conflict, dedupe tsconfig
- Update exports for 7 packages (babel-preset, postcss-syntax, jest-serializer, webpack-loader, webpack-extraction-plugin, next-extraction-plugin, eslint-plugin) to point to ./dist/ files, enabling @nx/js/typescript build target inference - Add cleanDeclarations rollup plugin to remove .d.ts files and .tsbuildinfo generated by rollup's TypeScript plugin, preventing conflicts with tsc --build - Remove duplicate compilerOptions entries in tsconfig.base.json (from merge) - Simplify packLocalPackage to pack from package root directory Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e5b213e commit 66e9762

10 files changed

Lines changed: 63 additions & 50 deletions

File tree

e2e/utils/src/packLocalPackage.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,21 @@
11
import * as path from 'path';
2-
import * as fs from 'fs';
32
import * as logSymbols from 'log-symbols';
43

54
import { sh } from './sh';
65

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-
156
export async function packLocalPackage(rootDir: string, tempDir: string, packageName: string) {
167
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));
198

20-
if (!distPathExists) {
21-
throw new Error(`A directory with artifacts (${distPath}) does not exist`);
9+
if (!packagePath) {
10+
throw new Error(`A package directory (${packageName}) does not exist`);
2211
}
2312

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-
2913
// Use `npm pack` because `yarn pack` incorrectly calculates the included files when the
3014
// files to include/exclude are specified by .npmignore rather than package.json `files`.
3115
// (--quiet outputs only the .tgz filename, not all the included files)
32-
const packFile = (await sh(`npm pack --quiet ${distPath}`, tempDir, true)).trim();
16+
const packFile = (await sh(`npm pack --quiet ${packagePath}`, tempDir, true)).trim();
3317
console.log(logSymbols.success, `Package "${packageName}" was packed`);
3418

35-
// Clean up the temporary package.json in dist
36-
await fs.promises.unlink(path.resolve(distPath, 'package.json'));
37-
3819
return {
3920
packageName,
4021
file: packFile,

packages/babel-preset/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@griffel/babel-preset",
33
"version": "1.8.0",
4-
"types": "./src/index.ts",
4+
"types": "./dist/index.d.ts",
55
"description": "Babel preset with build time transforms for Griffel",
66
"license": "MIT",
77
"repository": {
@@ -12,8 +12,8 @@
1212
"./package.json": "./package.json",
1313
".": {
1414
"@griffel/source": "./src/index.ts",
15-
"types": "./src/index.ts",
16-
"default": "./src/index.ts"
15+
"types": "./dist/index.d.ts",
16+
"default": "./dist/index.js"
1717
}
1818
},
1919
"devDependencies": {

packages/eslint-plugin/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@griffel/eslint-plugin",
33
"version": "2.0.2",
4-
"types": "./src/index.ts",
4+
"types": "./dist/index.d.ts",
55
"description": "ESLint plugin with lint rules for Griffel",
66
"license": "MIT",
77
"repository": {
@@ -12,8 +12,8 @@
1212
"./package.json": "./package.json",
1313
".": {
1414
"@griffel/source": "./src/index.ts",
15-
"types": "./src/index.ts",
16-
"default": "./src/index.ts"
15+
"types": "./dist/index.d.ts",
16+
"default": "./dist/index.js"
1717
}
1818
},
1919
"devDependencies": {

packages/jest-serializer/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@griffel/jest-serializer",
33
"version": "1.1.35",
4-
"types": "./src/index.ts",
4+
"types": "./dist/index.d.ts",
55
"description": "Jest serializer for Griffel",
66
"license": "MIT",
77
"repository": {
@@ -12,8 +12,8 @@
1212
"./package.json": "./package.json",
1313
".": {
1414
"@griffel/source": "./src/index.ts",
15-
"types": "./src/index.ts",
16-
"default": "./src/index.ts"
15+
"types": "./dist/index.d.ts",
16+
"default": "./dist/index.js"
1717
}
1818
},
1919
"devDependencies": {

packages/next-extraction-plugin/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@griffel/next-extraction-plugin",
33
"version": "0.1.14",
4-
"types": "./src/index.ts",
4+
"types": "./dist/index.d.ts",
55
"description": "NextJS plugin that add Griffel's CSS extraction to webpack loaders pipeline",
66
"license": "MIT",
77
"repository": {
@@ -12,8 +12,8 @@
1212
"./package.json": "./package.json",
1313
".": {
1414
"@griffel/source": "./src/index.ts",
15-
"types": "./src/index.ts",
16-
"default": "./src/index.ts"
15+
"types": "./dist/index.d.ts",
16+
"default": "./dist/index.js"
1717
}
1818
},
1919
"dependencies": {

packages/postcss-syntax/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@griffel/postcss-syntax",
33
"version": "1.3.5",
4-
"types": "./src/index.ts",
4+
"types": "./dist/index.d.ts",
55
"description": "postcss syntax for Griffel",
66
"license": "MIT",
77
"repository": {
@@ -21,9 +21,9 @@
2121
"./package.json": "./package.json",
2222
".": {
2323
"@griffel/source": "./src/index.ts",
24-
"types": "./src/index.ts",
25-
"default": "./src/index.ts"
24+
"types": "./dist/index.d.ts",
25+
"default": "./dist/index.js"
2626
}
2727
},
28-
"main": "./src/index.js"
28+
"main": "./dist/index.js"
2929
}

packages/webpack-extraction-plugin/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@griffel/webpack-extraction-plugin",
33
"version": "0.5.13",
4-
"types": "./src/index.ts",
4+
"types": "./dist/index.d.ts",
55
"description": "Webpack plugin that performs CSS extraction for Griffel",
66
"license": "MIT",
77
"repository": {
@@ -12,8 +12,8 @@
1212
"./package.json": "./package.json",
1313
".": {
1414
"@griffel/source": "./src/index.ts",
15-
"types": "./src/index.ts",
16-
"default": "./src/index.ts"
15+
"types": "./dist/index.d.ts",
16+
"default": "./dist/index.js"
1717
}
1818
},
1919
"devDependencies": {

packages/webpack-loader/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@griffel/webpack-loader",
33
"version": "2.2.22",
4-
"types": "./src/index.ts",
4+
"types": "./dist/index.d.ts",
55
"description": "Webpack loader that performs build time transforms for Griffel",
66
"license": "MIT",
77
"repository": {
@@ -12,8 +12,8 @@
1212
"./package.json": "./package.json",
1313
".": {
1414
"@griffel/source": "./src/index.ts",
15-
"types": "./src/index.ts",
16-
"default": "./src/index.ts"
15+
"types": "./dist/index.d.ts",
16+
"default": "./dist/index.js"
1717
}
1818
},
1919
"devDependencies": {

tools/getRollupOptions.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
11
const { preserveDirectives } = require('rollup-plugin-preserve-directives');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
/**
6+
* Rollup plugin that removes declaration files (.d.ts, .d.ts.map) generated by
7+
* @rollup/plugin-typescript. These are incompatible with tsc --build project references
8+
* (different directory layout), so tsc handles declarations via the type-check target instead.
9+
*/
10+
function cleanDeclarations() {
11+
return {
12+
name: 'clean-declarations',
13+
async writeBundle(outputOptions) {
14+
const dir = outputOptions.dir;
15+
if (!dir) return;
16+
17+
const srcDir = path.join(dir, 'src');
18+
if (fs.existsSync(srcDir)) {
19+
fs.rmSync(srcDir, { recursive: true });
20+
}
21+
22+
// Remove the barrel index.d.ts and stale .tsbuildinfo generated by rollup
23+
for (const file of fs.readdirSync(dir)) {
24+
if (file.endsWith('.d.ts') || file.endsWith('.d.ts.map')) {
25+
fs.unlinkSync(path.join(dir, file));
26+
}
27+
}
28+
29+
// Remove stale .tsbuildinfo from the package root (rollup's tsc pass creates it)
30+
const pkgRoot = path.dirname(dir);
31+
for (const file of fs.readdirSync(pkgRoot)) {
32+
if (file.endsWith('.tsbuildinfo')) {
33+
fs.unlinkSync(path.join(pkgRoot, file));
34+
}
35+
}
36+
},
37+
};
38+
}
239

340
function getRollupOptions(/** @type {import('rollup').RollupOptions} */ options) {
441
if (Array.isArray(options.output)) {
@@ -14,6 +51,7 @@ function getRollupOptions(/** @type {import('rollup').RollupOptions} */ options)
1451
// Add plugin to preserve 'use client' directives in the output files
1552
options.plugins = options.plugins || [];
1653
options.plugins.push(preserveDirectives());
54+
options.plugins.push(cleanDeclarations());
1755

1856
return options;
1957
}

tsconfig.base.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{
22
"compileOnSave": false,
33
"compilerOptions": {
4-
"forceConsistentCasingInFileNames": true,
5-
"strict": true,
6-
"noImplicitOverride": true,
7-
"noPropertyAccessFromIndexSignature": true,
8-
"noImplicitReturns": true,
9-
"noFallthroughCasesInSwitch": true,
104
"composite": true,
115
"sourceMap": true,
126
"declarationMap": true,

0 commit comments

Comments
 (0)