Skip to content

Commit 32aa6d2

Browse files
committed
chore(repo): central changes for Rollup 3 updates
1 parent 4e85ed7 commit 32aa6d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3041
-3539
lines changed

.eslintrc.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,15 @@ module.exports = {
77
rules: {
88
// disabling sort keys for now so we can get the rest of the linting shored up
99
'sort-keys': 'off',
10-
'typescript-sort-keys/interface': 'off'
10+
'typescript-sort-keys/interface': 'off',
11+
'import/extensions': 'off',
12+
'import/no-unresolved': 'off'
1113
},
1214
overrides: [
1315
{
1416
files: ['**/fixtures/**'],
1517
rules: {
16-
'no-console': 'off',
17-
'import/extensions': 'off',
18-
'import/no-unresolved': 'off'
19-
}
20-
},
21-
{
22-
files: ['**/test/**'],
23-
rules: {
24-
'import/extensions': 'off'
18+
'no-console': 'off'
2519
}
2620
}
2721
]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ coverage.lcov
1111
.idea
1212
.rollup.cache
1313

14+
!packages/*/test/**/node_modules
1415
!packages/node-resolve/test/fixtures/**/node_modules
1516
!packages/commonjs/test/**/node_modules
1617
!packages/typescript/test/fixtures/**/node_modules

package.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"private": true,
44
"scripts": {
55
"ci:coverage:submit": "node scripts/codecov",
6-
"fix:js": "eslint --cache packages scripts shared util --ext .js,.ts --fix",
6+
"fix:js": "eslint --cache packages scripts shared util --ext .js,.ts,.mjs --fix",
77
"lint": "pnpm lint:docs && pnpm --no-bail lint:json && pnpm lint:package && pnpm lint:js",
88
"lint:docs": "prettier --write .github/**/*.md **/README.md **/CHANGELOG.md",
9-
"lint:js": "eslint --cache packages scripts shared util --ext .js,.ts",
9+
"lint:js": "eslint --cache packages scripts shared util --ext .js,.ts,.mjs",
1010
"lint:json": "prettier --write .github/**/*.yml **/tsconfig.json tsconfig.*.json pnpm-workspace.yaml",
1111
"lint:package": "prettier --write **/package.json",
1212
"plugin:release": "ts-node ./scripts/release.ts",
@@ -18,32 +18,35 @@
1818
},
1919
"devDependencies": {
2020
"@ava/babel": "2.0.0",
21+
"@rollup/plugin-typescript": "^8.5.0",
2122
"@types/conventional-commits-parser": "^3.0.2",
23+
"@types/node": "14.18.30",
2224
"@types/semver": "^7.3.7",
2325
"@types/source-map-support": "^0.5.4",
2426
"@types/yargs-parser": "^20.2.1",
25-
"@typescript-eslint/eslint-plugin": "^4.9.0",
26-
"@typescript-eslint/parser": "^4.9.0",
27-
"ava": "^3.15.0",
27+
"@typescript-eslint/eslint-plugin": "^5.38.0",
28+
"@typescript-eslint/parser": "^5.38.0",
29+
"ava": "^4.3.3",
2830
"chalk": "^4.1.0",
2931
"codecov-lite": "2.0.0",
3032
"conventional-commits-parser": "^3.2.1",
31-
"del-cli": "4.0.0",
32-
"eslint-config-rollup": "^2.0.4",
33+
"del-cli": "^5.0.0",
34+
"eslint": "^8.24.0",
35+
"eslint-config-rollup": "^3.0.0",
3336
"esm": "^3.2.25",
3437
"execa": "^5.1.1",
3538
"globby": "^11.0.1",
3639
"husky": "8.0.1",
3740
"lint-staged": "11.0.1",
3841
"nyc": "^15.1.0",
3942
"pnpm": "^7.12.2",
40-
"prettier": "^2.2.1",
43+
"prettier": "^2.7.1",
4144
"prettier-plugin-package": "^1.3.0",
4245
"semver": "^7.3.2",
43-
"source-map-support": "^0.5.19",
46+
"source-map-support": "^0.5.21",
4447
"ts-node": "10.9.1",
4548
"tsconfig-paths": "^3.9.0",
46-
"typescript": "4.8.3",
49+
"typescript": "^4.8.3",
4750
"write-pkg": "^4.0.0",
4851
"yaml": "^1.10.0",
4952
"yargs-parser": "^20.2.9"

packages/alias/package.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,11 @@
5454
"@rollup/plugin-node-resolve": "^8.4.0",
5555
"@rollup/plugin-typescript": "^5.0.2",
5656
"del-cli": "^3.0.1",
57-
"rollup": "^2.67.3",
57+
"rollup": "2.67.3",
5858
"typescript": "^4.1.2"
5959
},
6060
"types": "types/index.d.ts",
6161
"ava": {
62-
"babel": {
63-
"compileEnhancements": false
64-
},
65-
"extensions": [
66-
"ts"
67-
],
68-
"require": [
69-
"ts-node/register"
70-
],
7162
"files": [
7263
"!**/fixtures/**",
7364
"!**/output/**",

packages/alias/test/node_modules/current-package

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/alias/test/test.js renamed to packages/alias/test/test.mjs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import path, { posix } from 'path';
2+
import { fileURLToPath } from 'url';
3+
import { createRequire } from 'module';
24

35
import test from 'ava';
46
import { rollup } from 'rollup';
5-
6-
// eslint-disable-next-line import/no-unresolved, import/extensions
77
import nodeResolvePlugin from '@rollup/plugin-node-resolve';
88

9-
import alias from '../dist';
9+
import alias from 'current-package';
1010

11-
const normalizePath = (pathToNormalize) => pathToNormalize;
12-
const DIRNAME = normalizePath(__dirname);
11+
const DIRNAME = fileURLToPath(new URL('.', import.meta.url));
1312

1413
/**
1514
* Helper function to test configuration with Rollup
@@ -197,9 +196,7 @@ test('Windows absolute path aliasing', (t) =>
197196
importer: posix.resolve(DIRNAME, './fixtures/index.js')
198197
}
199198
]
200-
).then((result) =>
201-
t.deepEqual(result, [normalizePath('E:\\react\\node_modules\\fbjs\\lib\\warning')])
202-
));
199+
).then((result) => t.deepEqual(result, ['E:\\react\\node_modules\\fbjs\\lib\\warning'])));
203200

204201
/**
205202
* Helper function to get moduleIDs from final Rollup bundle
@@ -211,7 +208,7 @@ const getModuleIdsFromBundle = (bundle) => {
211208
return Promise.resolve(bundle.modules.map((module) => module.id));
212209
}
213210
return bundle
214-
.generate({ format: 'esm' })
211+
.generate({ format: 'es' })
215212
.then((generated) => {
216213
if (generated.output) {
217214
return generated.output.length
@@ -565,3 +562,45 @@ test('CustomResolver plugin-like object with buildStart', (t) => {
565562
})
566563
);
567564
});
565+
566+
test('Works as CJS plugin', async (t) => {
567+
const require = createRequire(import.meta.url);
568+
const aliasCjs = require('current-package');
569+
const bundle = await rollup({
570+
input: './test/fixtures/index.js',
571+
plugins: [
572+
aliasCjs({
573+
entries: [
574+
{ find: 'fancyNumber', replacement: './aliasMe' },
575+
{
576+
find: './anotherFancyNumber',
577+
replacement: './localAliasMe'
578+
},
579+
{ find: 'numberFolder', replacement: './folder' },
580+
{
581+
find: './numberFolder',
582+
replacement: './folder'
583+
}
584+
]
585+
})
586+
]
587+
});
588+
const moduleIds = await getModuleIdsFromBundle(bundle);
589+
const normalizedIds = moduleIds.map((id) => path.resolve(id)).sort();
590+
t.is(normalizedIds.length, 5);
591+
[
592+
'/fixtures/aliasMe.js',
593+
'/fixtures/folder/anotherNumber.js',
594+
'/fixtures/index.js',
595+
'/fixtures/localAliasMe.js',
596+
'/fixtures/nonAliased.js'
597+
]
598+
.map((id) => path.normalize(id))
599+
.forEach((expectedId, index) =>
600+
t.is(
601+
normalizedIds[index].endsWith(expectedId),
602+
true,
603+
`expected ${normalizedIds[index]} to end with ${expectedId}`
604+
)
605+
);
606+
});

packages/buble/package.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,11 @@
5959
"del-cli": "^3.0.1",
6060
"rollup": "^2.67.3",
6161
"source-map": "^0.7.3",
62-
"typescript": "^4.1.2"
62+
"typescript": "4.1.2"
6363
},
6464
"types": "types/index.d.ts",
6565
"ava": {
66-
"babel": {
67-
"compileEnhancements": false
68-
},
69-
"extensions": [
70-
"ts"
71-
],
72-
"require": [
73-
"ts-node/register"
74-
],
66+
"workerThreads": false,
7567
"files": [
7668
"!**/fixtures/**",
7769
"!**/output/**",

packages/buble/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function buble(options: RollupBubleOptions = {}): Plugin {
1616

1717
try {
1818
return transform(code, transformOptions);
19-
} catch (e) {
19+
} catch (e: any) {
2020
e.plugin = 'buble';
2121
if (!e.loc) e.loc = {};
2222
e.loc.file = id;

packages/commonjs/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@
7676
},
7777
"types": "types/index.d.ts",
7878
"ava": {
79-
"babel": {
80-
"compileEnhancements": false
81-
},
79+
"workerThreads": false,
8280
"files": [
8381
"!**/fixtures/**",
8482
"!**/helpers/**",

packages/commonjs/src/resolve-require-sources.js

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre
140140
if (isWrappedId(resolved.id, ES_IMPORT_SUFFIX)) {
141141
return (
142142
(await getTypeForImportedModule(
143-
(await this.load({ id: resolved.id })).meta.commonjs.resolved,
143+
(
144+
await this.load({ id: resolved.id })
145+
).meta.commonjs.resolved,
144146
this.load
145147
)) !== IS_WRAPPED_COMMONJS
146148
);
@@ -151,61 +153,56 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre
151153
).some((shouldTransform) => shouldTransform);
152154
},
153155
/* eslint-disable no-param-reassign */
154-
resolveRequireSourcesAndUpdateMeta: (rollupContext) => async (
155-
parentId,
156-
isParentCommonJS,
157-
parentMeta,
158-
sources
159-
) => {
160-
parentMeta.initialCommonJSType = isParentCommonJS;
161-
parentMeta.requires = [];
162-
parentMeta.isRequiredCommonJS = Object.create(null);
163-
setInitialParentType(parentId, isParentCommonJS);
164-
const currentlyResolvingForParent = currentlyResolving.get(parentId) || new Set();
165-
currentlyResolving.set(parentId, currentlyResolvingForParent);
166-
const requireTargets = await Promise.all(
167-
sources.map(async ({ source, isConditional }) => {
168-
// Never analyze or proxy internal modules
169-
if (source.startsWith('\0')) {
170-
return { id: source, allowProxy: false };
171-
}
172-
currentlyResolvingForParent.add(source);
173-
const resolved =
174-
(await rollupContext.resolve(source, parentId, {
175-
custom: { 'node-resolve': { isRequire: true } }
176-
})) || resolveExtensions(source, parentId, extensions);
177-
currentlyResolvingForParent.delete(source);
178-
if (!resolved) {
179-
return { id: wrapId(source, EXTERNAL_SUFFIX), allowProxy: false };
180-
}
181-
const childId = resolved.id;
182-
if (resolved.external) {
183-
return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false };
184-
}
185-
parentMeta.requires.push({ resolved, isConditional });
186-
await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load);
187-
return { id: childId, allowProxy: true };
188-
})
189-
);
190-
parentMeta.isCommonJS = getTypeForFullyAnalyzedModule(parentId);
191-
fullyAnalyzedModules[parentId] = true;
192-
return requireTargets.map(({ id: dependencyId, allowProxy }, index) => {
193-
// eslint-disable-next-line no-multi-assign
194-
const isCommonJS = (parentMeta.isRequiredCommonJS[
195-
dependencyId
196-
] = getTypeForFullyAnalyzedModule(dependencyId));
197-
fullyAnalyzedModules[dependencyId] = true;
198-
return {
199-
source: sources[index].source,
200-
id: allowProxy
201-
? isCommonJS === IS_WRAPPED_COMMONJS
202-
? wrapId(dependencyId, WRAPPED_SUFFIX)
203-
: wrapId(dependencyId, PROXY_SUFFIX)
204-
: dependencyId,
205-
isCommonJS
206-
};
207-
});
208-
},
156+
resolveRequireSourcesAndUpdateMeta:
157+
(rollupContext) => async (parentId, isParentCommonJS, parentMeta, sources) => {
158+
parentMeta.initialCommonJSType = isParentCommonJS;
159+
parentMeta.requires = [];
160+
parentMeta.isRequiredCommonJS = Object.create(null);
161+
setInitialParentType(parentId, isParentCommonJS);
162+
const currentlyResolvingForParent = currentlyResolving.get(parentId) || new Set();
163+
currentlyResolving.set(parentId, currentlyResolvingForParent);
164+
const requireTargets = await Promise.all(
165+
sources.map(async ({ source, isConditional }) => {
166+
// Never analyze or proxy internal modules
167+
if (source.startsWith('\0')) {
168+
return { id: source, allowProxy: false };
169+
}
170+
currentlyResolvingForParent.add(source);
171+
const resolved =
172+
(await rollupContext.resolve(source, parentId, {
173+
custom: { 'node-resolve': { isRequire: true } }
174+
})) || resolveExtensions(source, parentId, extensions);
175+
currentlyResolvingForParent.delete(source);
176+
if (!resolved) {
177+
return { id: wrapId(source, EXTERNAL_SUFFIX), allowProxy: false };
178+
}
179+
const childId = resolved.id;
180+
if (resolved.external) {
181+
return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false };
182+
}
183+
parentMeta.requires.push({ resolved, isConditional });
184+
await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load);
185+
return { id: childId, allowProxy: true };
186+
})
187+
);
188+
parentMeta.isCommonJS = getTypeForFullyAnalyzedModule(parentId);
189+
fullyAnalyzedModules[parentId] = true;
190+
return requireTargets.map(({ id: dependencyId, allowProxy }, index) => {
191+
// eslint-disable-next-line no-multi-assign
192+
const isCommonJS = (parentMeta.isRequiredCommonJS[dependencyId] =
193+
getTypeForFullyAnalyzedModule(dependencyId));
194+
fullyAnalyzedModules[dependencyId] = true;
195+
return {
196+
source: sources[index].source,
197+
id: allowProxy
198+
? isCommonJS === IS_WRAPPED_COMMONJS
199+
? wrapId(dependencyId, WRAPPED_SUFFIX)
200+
: wrapId(dependencyId, PROXY_SUFFIX)
201+
: dependencyId,
202+
isCommonJS
203+
};
204+
});
205+
},
209206
isCurrentlyResolving(source, parentId) {
210207
const currentlyResolvingForParent = currentlyResolving.get(parentId);
211208
return currentlyResolvingForParent && currentlyResolvingForParent.has(source);

0 commit comments

Comments
 (0)