Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(estree-walker): bump estree-walker to v3 #1786

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion packages/commonjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"dependencies": {
"@rollup/pluginutils": "^5.0.1",
"commondir": "^1.0.1",
"estree-walker": "^2.0.2",
"estree-walker": "^3.0.3",
"fdir": "^6.2.0",
"is-reference": "1.2.1",
"magic-string": "^0.30.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ const { workerData, parentPort } = require('worker_threads');

const { rollup } = require('rollup');

const commonjs = require('../../../..');
const { getCodeFromBundle } = require('../../../helpers/util');

generateCode(workerData);

async function generateCode(cache) {
const commonjs = (await import('current-package')).default;
const { getCodeFromBundle } = await import('../../../helpers/util.mjs');
const code = await getCodeFromBundle(
await rollup({
input: 'fixtures/samples/caching/main.js',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
/* eslint-disable global-require, import/no-dynamic-require, no-console */

const fs = require('fs');
const path = require('path');
import * as fs from 'fs';
import { createRequire } from 'module';
import * as path from 'path';
import { fileURLToPath } from 'url';

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

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

process.chdir(__dirname);
const require = createRequire(import.meta.url);

process.chdir(fileURLToPath(new URL('.', import.meta.url)));

const transformContext = {
error: (base, props) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/* eslint-disable global-require, import/no-dynamic-require, no-console */

const { readdirSync } = require('fs');
import { readdirSync } from 'fs';
import { createRequire } from 'module';
import { fileURLToPath } from 'url';

const test = require('ava');
const { rollup } = require('rollup');
import test from 'ava';
import { rollup } from 'rollup';

const { commonjs, getCodeMapFromBundle, runCodeSplitTest } = require('./helpers/util');
import { commonjs, getCodeMapFromBundle, runCodeSplitTest } from './helpers/util.mjs';

process.chdir(__dirname);
const require = createRequire(import.meta.url);

process.chdir(fileURLToPath(new URL('.', import.meta.url)));

readdirSync('./fixtures/function').forEach((dir) => {
let config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const path = require('path');
import { createRequire } from 'module';
import * as path from 'path';

const commonjsPlugin = require('../..');
import commonjsPlugin from 'current-package';

function commonjs(options) {
delete require.cache[require.resolve('../..')];
const require = createRequire(import.meta.url);

export function commonjs(options) {
return commonjsPlugin(options);
}

function normalizePathSlashes(path) {
export function normalizePathSlashes(path) {
return path.replace(/\\/g, '/');
}

Expand All @@ -27,7 +29,7 @@ function requireWithContext(code, context) {
return contextWithExports.module.exports;
}

function runCodeSplitTest(codeMap, t, entryName = 'main.js', configContext = {}) {
export function runCodeSplitTest(codeMap, t, entryName = 'main.js', configContext = {}) {
const requireFromOutputVia = (importer) => (importee) => {
const outputId = path.posix.join(path.posix.dirname(importer), importee);
const code = codeMap[outputId];
Expand Down Expand Up @@ -63,7 +65,7 @@ function runCodeSplitTest(codeMap, t, entryName = 'main.js', configContext = {})
return { exports, global };
}

async function getCodeMapFromBundle(bundle, options = {}) {
export async function getCodeMapFromBundle(bundle, options = {}) {
const generated = await bundle.generate({
interop: 'compat',
exports: 'auto',
Expand All @@ -77,21 +79,12 @@ async function getCodeMapFromBundle(bundle, options = {}) {
return codeMap;
}

async function getCodeFromBundle(bundle, customOptions = {}) {
export async function getCodeFromBundle(bundle, customOptions = {}) {
const options = { exports: 'auto', format: 'cjs', ...customOptions };
return (await bundle.generate(options)).output[0].code;
}

async function executeBundle(bundle, t, { context, exports, testEntry = 'main.js' } = {}) {
export async function executeBundle(bundle, t, { context, exports, testEntry = 'main.js' } = {}) {
const codeMap = await getCodeMapFromBundle(bundle, exports ? { exports } : {});
return runCodeSplitTest(codeMap, t, testEntry, context);
}

module.exports = {
commonjs,
executeBundle,
getCodeFromBundle,
getCodeMapFromBundle,
normalizePathSlashes,
runCodeSplitTest
};
1 change: 1 addition & 0 deletions packages/commonjs/test/node_modules/current-package

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

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Snapshot report for `test/function.js`
# Snapshot report for `test/function.mjs`

The actual snapshot is saved in `function.js.snap`.
The actual snapshot is saved in `function.mjs.snap`.

Generated by [AVA](https://avajs.dev).

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Snapshot report for `test/test.js`
# Snapshot report for `test/test.mjs`

The actual snapshot is saved in `test.js.snap`.
The actual snapshot is saved in `test.mjs.snap`.

Generated by [AVA](https://avajs.dev).

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
/* eslint-disable line-comment-position, no-new-func, no-undefined */

const os = require('os');
const path = require('path');

const { nodeResolve } = require('@rollup/plugin-node-resolve');
const test = require('ava');
const { getLocator } = require('locate-character');
const { rollup } = require('rollup');
const { install } = require('source-map-support');

const { testBundle } = require('../../../util/test');

const { peerDependencies } = require('../package.json');

const {
import { createRequire } from 'module';
import * as os from 'os';
import * as path from 'path';
import { fileURLToPath } from 'url';

import { nodeResolve } from '@rollup/plugin-node-resolve';
import test from 'ava';
import { getLocator } from 'locate-character';
import { rollup } from 'rollup';
import { install } from 'source-map-support';

import {
commonjs,
executeBundle,
getCodeFromBundle,
normalizePathSlashes
} = require('./helpers/util.js');
} from './helpers/util.mjs';

const require = createRequire(import.meta.url);

const { peerDependencies } = require('../package.json');

const { testBundle } = require('../../../util/test.js');

install();
test.beforeEach(() => process.chdir(__dirname));
test.beforeEach(() => process.chdir(fileURLToPath(new URL('.', import.meta.url))));

const loader = (modules) => {
return {
Expand Down Expand Up @@ -228,7 +232,7 @@ test.serial('handles symlinked node_modules with preserveSymlinks: false', (t) =

// ensure we resolve starting from a directory with
// symlinks in node_modules.
process.chdir(path.join(__dirname, 'fixtures/samples/symlinked-node-modules'));
process.chdir(fileURLToPath(new URL('fixtures/samples/symlinked-node-modules', import.meta.url)));

return t.notThrowsAsync(
rollup({
Expand Down Expand Up @@ -652,7 +656,7 @@ if (Number(/^v(\d+)/.exec(process.version)[1]) >= 12) {
// We do a second run in a worker so that all internal state is cleared
const { Worker } = await import('worker_threads');
const getRollupUpCodeWithCache = new Worker(
path.join(__dirname, 'fixtures/samples/caching/rollupWorker.js'),
fileURLToPath(new URL('fixtures/samples/caching/rollupWorker.js', import.meta.url)),
{
workerData: cache
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dynamic-import-vars/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"dependencies": {
"@rollup/pluginutils": "^5.0.1",
"astring": "^1.8.5",
"estree-walker": "^2.0.2",
"estree-walker": "^3.0.3",
"fast-glob": "^3.2.12",
"magic-string": "^0.30.3"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/* eslint-disable import/no-unresolved */

const { join } = require('path');
import { posix } from 'path';
import { fileURLToPath } from 'url';

const test = require('ava');
const { rollup } = require('rollup');
import test from 'ava';
import { rollup } from 'rollup';

const dynamicImportVars = require('current-package');
import dynamicImportVars from 'current-package';

process.chdir(join(__dirname, 'fixtures'));
const DIRNAME = fileURLToPath(new URL('.', import.meta.url));

process.chdir(fileURLToPath(new URL('fixtures', import.meta.url)));

test('single dir', async (t) => {
const bundle = await rollup({
Expand All @@ -16,9 +19,9 @@ test('single dir', async (t) => {
});
const { output } = await bundle.generate({ format: 'es' });
const expectedFiles = [
require.resolve('./fixtures/fixture-single-dir.js'),
require.resolve('./fixtures/module-dir-a/module-a-1.js'),
require.resolve('./fixtures/module-dir-a/module-a-2.js')
posix.resolve(DIRNAME, './fixtures/fixture-single-dir.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-1.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js')
];

t.deepEqual(
Expand All @@ -35,12 +38,12 @@ test('multiple dirs', async (t) => {
});
const { output } = await bundle.generate({ format: 'es' });
const expectedFiles = [
require.resolve('./fixtures/fixture-multiple-dirs.js'),
require.resolve('./fixtures/module-dir-a/module-a-1.js'),
require.resolve('./fixtures/module-dir-a/module-a-2.js'),
require.resolve('./fixtures/module-dir-b/module-b-1.js'),
require.resolve('./fixtures/module-dir-b/module-b-2.js'),
require.resolve('./fixtures/sub-dir/fixture-upwards-path.js')
posix.resolve(DIRNAME, './fixtures/fixture-multiple-dirs.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-1.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-b/module-b-1.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-b/module-b-2.js'),
posix.resolve(DIRNAME, './fixtures/sub-dir/fixture-upwards-path.js')
];

t.deepEqual(
Expand All @@ -57,9 +60,9 @@ test('upwards dir path', async (t) => {
});
const { output } = await bundle.generate({ format: 'es' });
const expectedFiles = [
require.resolve('./fixtures/sub-dir/fixture-upwards-path.js'),
require.resolve('./fixtures/module-dir-a/module-a-1.js'),
require.resolve('./fixtures/module-dir-a/module-a-2.js')
posix.resolve(DIRNAME, './fixtures/sub-dir/fixture-upwards-path.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-1.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js')
];

t.deepEqual(
Expand All @@ -76,11 +79,11 @@ test('complex concatenation', async (t) => {
});
const { output } = await bundle.generate({ format: 'es' });
const expectedFiles = [
require.resolve('./fixtures/fixture-complex-concat.js'),
require.resolve('./fixtures/module-dir-a/module-a-1.js'),
require.resolve('./fixtures/module-dir-a/module-a-2.js'),
require.resolve('./fixtures/module-dir-b/module-b-1.js'),
require.resolve('./fixtures/module-dir-b/module-b-2.js')
posix.resolve(DIRNAME, './fixtures/fixture-complex-concat.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-1.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-b/module-b-1.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-b/module-b-2.js')
];

t.deepEqual(
Expand All @@ -97,9 +100,9 @@ test('own directory', async (t) => {
});
const { output } = await bundle.generate({ format: 'es' });
const expectedFiles = [
require.resolve('./fixtures/fixture-own-dir.js'),
require.resolve('./fixtures/root-module-a.js'),
require.resolve('./fixtures/root-module-b.js')
posix.resolve(DIRNAME, './fixtures/fixture-own-dir.js'),
posix.resolve(DIRNAME, './fixtures/root-module-a.js'),
posix.resolve(DIRNAME, './fixtures/root-module-b.js')
];

t.deepEqual(
Expand All @@ -116,12 +119,12 @@ test('multiple dynamic imports', async (t) => {
});
const { output } = await bundle.generate({ format: 'es' });
const expectedFiles = [
require.resolve('./fixtures/fixture-multiple-imports.js'),
require.resolve('./fixtures/module-dir-a/module-a-1.js'),
require.resolve('./fixtures/module-dir-a/module-a-2.js'),
require.resolve('./fixtures/module-dir-b/module-b-1.js'),
require.resolve('./fixtures/module-dir-b/module-b-2.js'),
require.resolve('./fixtures/sub-dir/fixture-upwards-path.js')
posix.resolve(DIRNAME, './fixtures/fixture-multiple-imports.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-1.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-b/module-b-1.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-b/module-b-2.js'),
posix.resolve(DIRNAME, './fixtures/sub-dir/fixture-upwards-path.js')
];

t.deepEqual(
Expand All @@ -138,8 +141,8 @@ test("doesn't change imports that should not be changed", async (t) => {
});
const { output } = await bundle.generate({ format: 'es' });
const expectedFiles = [
require.resolve('./fixtures/fixture-unchanged.js'),
require.resolve('./fixtures/module-dir-a/module-a-2.js')
posix.resolve(DIRNAME, './fixtures/fixture-unchanged.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js')
];

t.deepEqual(
Expand All @@ -160,7 +163,7 @@ test('can exclude files', async (t) => {
});
const { output } = await bundle.generate({ format: 'es' });

const expectedFiles = [require.resolve('./fixtures/fixture-excluded.js')];
const expectedFiles = [posix.resolve(DIRNAME, './fixtures/fixture-excluded.js')];

t.deepEqual(
expectedFiles,
Expand Down Expand Up @@ -193,9 +196,9 @@ test('dynamic imports assertions', async (t) => {
});
const { output } = await bundle.generate({ format: 'es' });
const expectedFiles = [
require.resolve('./fixtures/fixture-assert.js'),
require.resolve('./fixtures/module-dir-a/module-a-1.js'),
require.resolve('./fixtures/module-dir-a/module-a-2.js')
posix.resolve(DIRNAME, './fixtures/fixture-assert.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-1.js'),
posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js')
];

t.deepEqual(
Expand Down Expand Up @@ -228,7 +231,8 @@ test('throws if no files in dir when `errorWhenNoFilesFound` is set', async (t)
} catch (error) {
t.deepEqual(
error.message,
`No files found in ./module-dir-c/*.js when trying to dynamically load concatted string from ${require.resolve(
`No files found in ./module-dir-c/*.js when trying to dynamically load concatted string from ${posix.resolve(
DIRNAME,
'./fixtures/fixture-no-files.js'
)}`
);
Expand All @@ -245,7 +249,8 @@ test('warns if no files in dir when `errorWhenNoFilesFound` and `warnOnError` ar
onwarn(warning) {
t.deepEqual(
warning.message,
`No files found in ./module-dir-c/*.js when trying to dynamically load concatted string from ${require.resolve(
`No files found in ./module-dir-c/*.js when trying to dynamically load concatted string from ${posix.resolve(
DIRNAME,
'./fixtures/fixture-no-files.js'
)}`
);
Expand Down
Loading