Skip to content
Open
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
27 changes: 22 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions packages/plugin-webpack-filter/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import path from 'node:path';
import { defineConfig } from 'rollup';

import commonjsPlugin from '@rollup/plugin-commonjs';
import nodeResolvePlugin from '@rollup/plugin-node-resolve';
import typescriptPlugin from '@rollup/plugin-typescript';

const CONTEXT = path.join(process.cwd(), './src');
const CONTEXT_DIR = path.join(process.cwd(), './src');
const OUTPUT_DIR = 'lib';

export default defineConfig([
{
context: CONTEXT,
context: CONTEXT_DIR,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Remove Rollup “context” — it’s not a directory path

Rollup’s config option context sets the top-level this binding during bundling; passing a filesystem path here is misleading and not what the option is for. It’s safe to drop it for both outputs.

Apply:

-    context: CONTEXT_DIR,
+    // context not needed; use default module semantics

To verify repo-wide, search for any other misuse:

Also applies to: 38-38


🏁 Script executed:

#!/bin/bash
fd -t f "rollup.config.*" | xargs -I{} rg -n --no-heading "^\s*context\s*:" {}

Length of output: 221


🏁 Script executed:

#!/bin/bash
# Search all Rollup config files for any context usages, including file names
fd -t f "rollup.config.*" | xargs -I{} rg -n "^\s*context\s*:" {}

Length of output: 208


🏁 Script executed:

#!/bin/bash
# List all occurrences of `context:` in Rollup config files with file paths
rg -nH '^\s*context\s*:' -g 'rollup.config.*'

Length of output: 425


Drop misused Rollup context option across plugin configs

Rollup’s context option sets the top-level this binding during bundling; passing a filesystem path here is misleading. We can safely remove it (or replace with a comment) in all outputs:

• packages/rollup-plugin/rollup.config.mjs (line 13)
• packages/plugin-webpack-filter/rollup.config.mjs (lines 12, 38)
• packages/plugin-webpack-validate/rollup.config.mjs (lines 13, 38)

Apply the same diff in each file:

-    context: CONTEXT_DIR,
+    // context not needed; use default module semantics

-    context: CONTEXT,
+    // context not needed; use default module semantics

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/plugin-webpack-filter/rollup.config.mjs at line 12, the Rollup
`context` option is incorrectly set to a filesystem path, which is misleading
because `context` should define the top-level `this` binding. Remove the
`context: CONTEXT_DIR,` line entirely from the config to fix this misuse. Also,
apply the same removal to the specified lines in the other mentioned files for
consistency.

input: './src/index.ts',
output: {
dir: OUTPUT_DIR,
format: 'cjs',
entryFileNames: 'cjs/[name].js',
sourcemap: true,
preserveModules: true,
preserveModulesRoot: CONTEXT,
preserveModulesRoot: CONTEXT_DIR,
interop: 'auto',
},
external: /node_modules/,
Expand All @@ -36,26 +35,23 @@ export default defineConfig([
],
},
{
context: CONTEXT,
context: CONTEXT_DIR,
input: './src/index.ts',
output: {
dir: OUTPUT_DIR,
format: 'esm',
entryFileNames: 'esm/[name].js',
sourcemap: true,
preserveModules: true,
preserveModulesRoot: CONTEXT,
preserveModulesRoot: CONTEXT_DIR,
interop: 'auto',
},
external: /node_modules/,
plugins: [
nodeResolvePlugin({
extensions: ['.js', '.mjs', '.cjs', '.json'],
}),
commonjsPlugin({
// defaultIsModuleExports: 'auto',
// transformMixedEsModules: true,
}),
commonjsPlugin(),
typescriptPlugin({
tsconfig: './tsconfig.esm.json',
exclude: /\.test.ts/,
Expand Down
16 changes: 13 additions & 3 deletions packages/rollup-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"name": "rollup-plugin-bundle-stats",
"version": "4.21.2",
"description": "In-depth bundle analyzer for rollup(bundle size, assets, modules, packages)",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts",
"sideEffects": false,
"engines": {
"node": ">= 16.0"
Expand All @@ -12,7 +13,8 @@
"lib": "lib"
},
"scripts": {
"build": "npm run clean && rollup -c",
"build": "npm run clean && rollup -c && npm run build-type",
"build-type": "echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json && echo '{\"type\":\"module\"}' > lib/esm/package.json",
"clean": "rimraf lib",
"lint": "eslint",
"test:package": "cd test/package && npm test --"
Expand Down Expand Up @@ -46,9 +48,17 @@
"homepage": "https://github.com/relative-ci/bundle-stats/blob/master/packages/rollup-plugin#readme",
"dependencies": {
"@bundle-stats/cli-utils": "^4.21.2",
"@rollup/plugin-json": "6.1.0",
"rollup-plugin-webpack-stats": "2.1.3",
"tslib": "2.8.1"
},
"exports": {
".": {
"require": "./lib/cjs/index.js",
"import": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts"
}
},
"devDependencies": {
"@rollup/plugin-commonjs": "28.0.6",
"@rollup/plugin-node-resolve": "16.0.1",
Expand Down
48 changes: 42 additions & 6 deletions packages/rollup-plugin/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,30 +1,66 @@
import path from 'node:path';
import { defineConfig } from 'rollup';
import { nodeResolve as nodeResolvePlugin } from '@rollup/plugin-node-resolve';
import commonjsPlugin from '@rollup/plugin-commonjs';
import typescriptPlugin from '@rollup/plugin-typescript';
import jsonPlugin from '@rollup/plugin-json';

const OUTPUT_DIR = './lib';
const CONTEXT_DIR = './src';
const CONTEXT_DIR = path.join(process.cwd(), './src');
const OUTPUT_DIR = 'lib';

export default defineConfig([
{
context: CONTEXT_DIR,
input: './src/index.ts',
output: [
{
dir: OUTPUT_DIR,
format: 'cjs',
entryFileNames: '[name].js',
entryFileNames: 'cjs/[name].js',
sourcemap: true,
preserveModules: true,
preserveModulesRoot: CONTEXT_DIR,
interop: 'auto',
},
],
external: [/node_modules/],
external: [/node_modules/, /@bundle-stats/],
plugins: [
nodeResolvePlugin(),
nodeResolvePlugin({
extensions: ['.js', '.cjs', '.json'],
}),
commonjsPlugin({
defaultIsModuleExports: 'auto',
}),
jsonPlugin(),
typescriptPlugin({
tsconfig: './tsconfig.cjs.json',
exclude: /\.test.ts/,
}),
],
},
{
input: './src/index.ts',
output: [
{
dir: OUTPUT_DIR,
format: 'esm',
entryFileNames: 'esm/[name].js',
sourcemap: true,
preserveModules: true,
preserveModulesRoot: CONTEXT_DIR,
interop: 'auto',
},
],
external: [/node_modules/, /@bundle-stats/],
plugins: [
nodeResolvePlugin({
extensions: ['.js', '.mjs', '.cjs', '.json'],
}),
commonjsPlugin(),
jsonPlugin(),
typescriptPlugin({
tsconfig: './tsconfig.base.json',
tsconfig: './tsconfig.esm.json',
exclude: /\.test.ts/,
}),
],
},
Expand Down
3 changes: 1 addition & 2 deletions packages/rollup-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as path from 'path';
import * as fs from 'fs/promises';
import { Plugin } from 'rollup';
// @ts-ignore
import { type Plugin } from 'rollup';
import { bundleToWebpackStats } from 'rollup-plugin-webpack-stats/transform';
import { ReportOptions, generateReports } from '@bundle-stats/cli-utils';

Expand Down
31 changes: 25 additions & 6 deletions packages/rollup-plugin/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
{
"extends": "@tsconfig/node16/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"module": "Node16",
/* dirs */
"rootDir": "./src",
"declarationDir": "./lib/types",
"types": ["node", "jest"],
/* module config */
"target": "es2020",
"lib": ["es2020", "es2022.error"],
"resolveJsonModule": true,
"esModuleInterop": true,
/* behaviour options */
"strict": true,
"allowJs": true,
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"declaration": true,
"declarationDir": "./lib",
"sourceMap": true,
"noImplicitReturns": true,
"noImplicitOverride": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true
},
"include": ["src/**/*"],
"exclude": ["**/*.test.ts"]
"include": ["src"],
"exclude": ["node_modules", "lib"]
}
6 changes: 6 additions & 0 deletions packages/rollup-plugin/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "./lib/cjs"
}
}
6 changes: 6 additions & 0 deletions packages/rollup-plugin/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "./lib/esm"
}
}
13 changes: 2 additions & 11 deletions packages/rollup-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node",
"allowJs": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"lib": ["es2020"]
},
"ts-node": {
"compilerOptions": {
"module": "CommonJS"
}
"outDir": "./lib"
}
}
Loading