Skip to content

Commit

Permalink
chore(repo): central changes for Rollup 3 updates (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert authored Oct 7, 2022
1 parent 4e85ed7 commit 69146cd
Show file tree
Hide file tree
Showing 53 changed files with 3,041 additions and 3,539 deletions.
14 changes: 4 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@ module.exports = {
rules: {
// disabling sort keys for now so we can get the rest of the linting shored up
'sort-keys': 'off',
'typescript-sort-keys/interface': 'off'
'typescript-sort-keys/interface': 'off',
'import/extensions': 'off',
'import/no-unresolved': 'off'
},
overrides: [
{
files: ['**/fixtures/**'],
rules: {
'no-console': 'off',
'import/extensions': 'off',
'import/no-unresolved': 'off'
}
},
{
files: ['**/test/**'],
rules: {
'import/extensions': 'off'
'no-console': 'off'
}
}
]
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ coverage.lcov
.idea
.rollup.cache

!packages/*/test/**/node_modules
!packages/node-resolve/test/fixtures/**/node_modules
!packages/commonjs/test/**/node_modules
!packages/typescript/test/fixtures/**/node_modules
Expand Down
23 changes: 13 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"private": true,
"scripts": {
"ci:coverage:submit": "node scripts/codecov",
"fix:js": "eslint --cache packages scripts shared util --ext .js,.ts --fix",
"fix:js": "eslint --cache packages scripts shared util --ext .js,.ts,.mjs --fix",
"lint": "pnpm lint:docs && pnpm --no-bail lint:json && pnpm lint:package && pnpm lint:js",
"lint:docs": "prettier --write .github/**/*.md **/README.md **/CHANGELOG.md",
"lint:js": "eslint --cache packages scripts shared util --ext .js,.ts",
"lint:js": "eslint --cache packages scripts shared util --ext .js,.ts,.mjs",
"lint:json": "prettier --write .github/**/*.yml **/tsconfig.json tsconfig.*.json pnpm-workspace.yaml",
"lint:package": "prettier --write **/package.json",
"plugin:release": "ts-node ./scripts/release.ts",
Expand All @@ -18,32 +18,35 @@
},
"devDependencies": {
"@ava/babel": "2.0.0",
"@rollup/plugin-typescript": "^8.5.0",
"@types/conventional-commits-parser": "^3.0.2",
"@types/node": "14.18.30",
"@types/semver": "^7.3.7",
"@types/source-map-support": "^0.5.4",
"@types/yargs-parser": "^20.2.1",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"@typescript-eslint/parser": "^4.9.0",
"ava": "^3.15.0",
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
"ava": "^4.3.3",
"chalk": "^4.1.0",
"codecov-lite": "2.0.0",
"conventional-commits-parser": "^3.2.1",
"del-cli": "4.0.0",
"eslint-config-rollup": "^2.0.4",
"del-cli": "^5.0.0",
"eslint": "^8.24.0",
"eslint-config-rollup": "^3.0.0",
"esm": "^3.2.25",
"execa": "^5.1.1",
"globby": "^11.0.1",
"husky": "8.0.1",
"lint-staged": "11.0.1",
"nyc": "^15.1.0",
"pnpm": "^7.12.2",
"prettier": "^2.2.1",
"prettier": "^2.7.1",
"prettier-plugin-package": "^1.3.0",
"semver": "^7.3.2",
"source-map-support": "^0.5.19",
"source-map-support": "^0.5.21",
"ts-node": "10.9.1",
"tsconfig-paths": "^3.9.0",
"typescript": "4.8.3",
"typescript": "^4.8.3",
"write-pkg": "^4.0.0",
"yaml": "^1.10.0",
"yargs-parser": "^20.2.9"
Expand Down
11 changes: 1 addition & 10 deletions packages/alias/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,11 @@
"@rollup/plugin-node-resolve": "^8.4.0",
"@rollup/plugin-typescript": "^5.0.2",
"del-cli": "^3.0.1",
"rollup": "^2.67.3",
"rollup": "2.67.3",
"typescript": "^4.1.2"
},
"types": "types/index.d.ts",
"ava": {
"babel": {
"compileEnhancements": false
},
"extensions": [
"ts"
],
"require": [
"ts-node/register"
],
"files": [
"!**/fixtures/**",
"!**/output/**",
Expand Down
1 change: 1 addition & 0 deletions packages/alias/test/node_modules/current-package

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

57 changes: 48 additions & 9 deletions packages/alias/test/test.js → packages/alias/test/test.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import path, { posix } from 'path';
import { fileURLToPath } from 'url';
import { createRequire } from 'module';

import test from 'ava';
import { rollup } from 'rollup';

// eslint-disable-next-line import/no-unresolved, import/extensions
import nodeResolvePlugin from '@rollup/plugin-node-resolve';

import alias from '../dist';
import alias from 'current-package';

const normalizePath = (pathToNormalize) => pathToNormalize;
const DIRNAME = normalizePath(__dirname);
const DIRNAME = fileURLToPath(new URL('.', import.meta.url));

/**
* Helper function to test configuration with Rollup
Expand Down Expand Up @@ -197,9 +196,7 @@ test('Windows absolute path aliasing', (t) =>
importer: posix.resolve(DIRNAME, './fixtures/index.js')
}
]
).then((result) =>
t.deepEqual(result, [normalizePath('E:\\react\\node_modules\\fbjs\\lib\\warning')])
));
).then((result) => t.deepEqual(result, ['E:\\react\\node_modules\\fbjs\\lib\\warning'])));

/**
* Helper function to get moduleIDs from final Rollup bundle
Expand All @@ -211,7 +208,7 @@ const getModuleIdsFromBundle = (bundle) => {
return Promise.resolve(bundle.modules.map((module) => module.id));
}
return bundle
.generate({ format: 'esm' })
.generate({ format: 'es' })
.then((generated) => {
if (generated.output) {
return generated.output.length
Expand Down Expand Up @@ -565,3 +562,45 @@ test('CustomResolver plugin-like object with buildStart', (t) => {
})
);
});

test('Works as CJS plugin', async (t) => {
const require = createRequire(import.meta.url);
const aliasCjs = require('current-package');
const bundle = await rollup({
input: './test/fixtures/index.js',
plugins: [
aliasCjs({
entries: [
{ find: 'fancyNumber', replacement: './aliasMe' },
{
find: './anotherFancyNumber',
replacement: './localAliasMe'
},
{ find: 'numberFolder', replacement: './folder' },
{
find: './numberFolder',
replacement: './folder'
}
]
})
]
});
const moduleIds = await getModuleIdsFromBundle(bundle);
const normalizedIds = moduleIds.map((id) => path.resolve(id)).sort();
t.is(normalizedIds.length, 5);
[
'/fixtures/aliasMe.js',
'/fixtures/folder/anotherNumber.js',
'/fixtures/index.js',
'/fixtures/localAliasMe.js',
'/fixtures/nonAliased.js'
]
.map((id) => path.normalize(id))
.forEach((expectedId, index) =>
t.is(
normalizedIds[index].endsWith(expectedId),
true,
`expected ${normalizedIds[index]} to end with ${expectedId}`
)
);
});
12 changes: 2 additions & 10 deletions packages/buble/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,11 @@
"del-cli": "^3.0.1",
"rollup": "^2.67.3",
"source-map": "^0.7.3",
"typescript": "^4.1.2"
"typescript": "4.1.2"
},
"types": "types/index.d.ts",
"ava": {
"babel": {
"compileEnhancements": false
},
"extensions": [
"ts"
],
"require": [
"ts-node/register"
],
"workerThreads": false,
"files": [
"!**/fixtures/**",
"!**/output/**",
Expand Down
2 changes: 1 addition & 1 deletion packages/buble/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function buble(options: RollupBubleOptions = {}): Plugin {

try {
return transform(code, transformOptions);
} catch (e) {
} catch (e: any) {
e.plugin = 'buble';
if (!e.loc) e.loc = {};
e.loc.file = id;
Expand Down
4 changes: 1 addition & 3 deletions packages/commonjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@
},
"types": "types/index.d.ts",
"ava": {
"babel": {
"compileEnhancements": false
},
"workerThreads": false,
"files": [
"!**/fixtures/**",
"!**/helpers/**",
Expand Down
109 changes: 53 additions & 56 deletions packages/commonjs/src/resolve-require-sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre
if (isWrappedId(resolved.id, ES_IMPORT_SUFFIX)) {
return (
(await getTypeForImportedModule(
(await this.load({ id: resolved.id })).meta.commonjs.resolved,
(
await this.load({ id: resolved.id })
).meta.commonjs.resolved,
this.load
)) !== IS_WRAPPED_COMMONJS
);
Expand All @@ -151,61 +153,56 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre
).some((shouldTransform) => shouldTransform);
},
/* eslint-disable no-param-reassign */
resolveRequireSourcesAndUpdateMeta: (rollupContext) => async (
parentId,
isParentCommonJS,
parentMeta,
sources
) => {
parentMeta.initialCommonJSType = isParentCommonJS;
parentMeta.requires = [];
parentMeta.isRequiredCommonJS = Object.create(null);
setInitialParentType(parentId, isParentCommonJS);
const currentlyResolvingForParent = currentlyResolving.get(parentId) || new Set();
currentlyResolving.set(parentId, currentlyResolvingForParent);
const requireTargets = await Promise.all(
sources.map(async ({ source, isConditional }) => {
// Never analyze or proxy internal modules
if (source.startsWith('\0')) {
return { id: source, allowProxy: false };
}
currentlyResolvingForParent.add(source);
const resolved =
(await rollupContext.resolve(source, parentId, {
custom: { 'node-resolve': { isRequire: true } }
})) || resolveExtensions(source, parentId, extensions);
currentlyResolvingForParent.delete(source);
if (!resolved) {
return { id: wrapId(source, EXTERNAL_SUFFIX), allowProxy: false };
}
const childId = resolved.id;
if (resolved.external) {
return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false };
}
parentMeta.requires.push({ resolved, isConditional });
await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load);
return { id: childId, allowProxy: true };
})
);
parentMeta.isCommonJS = getTypeForFullyAnalyzedModule(parentId);
fullyAnalyzedModules[parentId] = true;
return requireTargets.map(({ id: dependencyId, allowProxy }, index) => {
// eslint-disable-next-line no-multi-assign
const isCommonJS = (parentMeta.isRequiredCommonJS[
dependencyId
] = getTypeForFullyAnalyzedModule(dependencyId));
fullyAnalyzedModules[dependencyId] = true;
return {
source: sources[index].source,
id: allowProxy
? isCommonJS === IS_WRAPPED_COMMONJS
? wrapId(dependencyId, WRAPPED_SUFFIX)
: wrapId(dependencyId, PROXY_SUFFIX)
: dependencyId,
isCommonJS
};
});
},
resolveRequireSourcesAndUpdateMeta:
(rollupContext) => async (parentId, isParentCommonJS, parentMeta, sources) => {
parentMeta.initialCommonJSType = isParentCommonJS;
parentMeta.requires = [];
parentMeta.isRequiredCommonJS = Object.create(null);
setInitialParentType(parentId, isParentCommonJS);
const currentlyResolvingForParent = currentlyResolving.get(parentId) || new Set();
currentlyResolving.set(parentId, currentlyResolvingForParent);
const requireTargets = await Promise.all(
sources.map(async ({ source, isConditional }) => {
// Never analyze or proxy internal modules
if (source.startsWith('\0')) {
return { id: source, allowProxy: false };
}
currentlyResolvingForParent.add(source);
const resolved =
(await rollupContext.resolve(source, parentId, {
custom: { 'node-resolve': { isRequire: true } }
})) || resolveExtensions(source, parentId, extensions);
currentlyResolvingForParent.delete(source);
if (!resolved) {
return { id: wrapId(source, EXTERNAL_SUFFIX), allowProxy: false };
}
const childId = resolved.id;
if (resolved.external) {
return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false };
}
parentMeta.requires.push({ resolved, isConditional });
await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load);
return { id: childId, allowProxy: true };
})
);
parentMeta.isCommonJS = getTypeForFullyAnalyzedModule(parentId);
fullyAnalyzedModules[parentId] = true;
return requireTargets.map(({ id: dependencyId, allowProxy }, index) => {
// eslint-disable-next-line no-multi-assign
const isCommonJS = (parentMeta.isRequiredCommonJS[dependencyId] =
getTypeForFullyAnalyzedModule(dependencyId));
fullyAnalyzedModules[dependencyId] = true;
return {
source: sources[index].source,
id: allowProxy
? isCommonJS === IS_WRAPPED_COMMONJS
? wrapId(dependencyId, WRAPPED_SUFFIX)
: wrapId(dependencyId, PROXY_SUFFIX)
: dependencyId,
isCommonJS
};
});
},
isCurrentlyResolving(source, parentId) {
const currentlyResolvingForParent = currentlyResolving.get(parentId);
return currentlyResolvingForParent && currentlyResolvingForParent.has(source);
Expand Down
10 changes: 5 additions & 5 deletions packages/commonjs/test/form.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable global-require, import/no-dynamic-require, no-console */

import * as fs from 'fs';
import * as path from 'path';
const fs = require('fs');
const path = require('path');

import * as acorn from 'acorn';
import test from 'ava';
const acorn = require('acorn');
const test = require('ava');

import { commonjs } from './helpers/util';
const { commonjs } = require('./helpers/util.js');

process.chdir(__dirname);

Expand Down
Loading

0 comments on commit 69146cd

Please sign in to comment.