Skip to content

Commit

Permalink
chore: upgrade deps
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop support of Node.js < v18
  • Loading branch information
3cp committed Sep 17, 2024
1 parent 1a47d3d commit c723de6
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 43 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/fixtures/src/x.js → fixtures/src/x.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const _ = require('lodash');
import _ from 'lodash';
export default class X {
constructor() {
this.name = 'Hello';
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/fixtures/y.js.map → fixtures/y.js.map

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

5 changes: 3 additions & 2 deletions lib/shared.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const fs = require('fs');
const path = require('path');
const fetch = require('node-fetch');
const crypto = require('crypto');
const {ensureParsed} = require('ast-matcher');
const convert = require('convert-source-map');
Expand Down Expand Up @@ -113,7 +112,9 @@ function getSourceMap(contents, filePath) {
if (converter) return converter.sourcemap;

if (filePath) {
converter = convert.fromMapFileSource(contents, dir);
converter = convert.fromMapFileSource(contents, (filename) =>
fs.readFileSync(path.resolve(dir, filename), 'utf-8')
);
if (converter) return converter.sourcemap;
}
} catch (err) {
Expand Down
31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
"./lib/resolve-package.js": "./lib/resolve-package-browser.js"
},
"engines": {
"node": ">=14.18.0"
"node": ">=18.0.0"
},
"scripts": {
"lint": "eslint index.js lib test",
"preversion": "npm test",
"version": "standard-changelog && git add CHANGELOG.md",
"postversion": "git push && git push --tags && npm publish",
"pretest": "npm run lint",
"test:node": "pta test/hide-log.js \"test/**/*.spec.js\"",
"coverage": "c8 pta test/hide-log.js \"test/**/*.spec.js\"",
"test:node": "pta",
"coverage": "c8 pta",
"pretest:browser": "gulp",
"test:browser": "browser-do --tap < dist/entry-bundle.js",
"test": "npm run test:node && npm run test:browser"
Expand All @@ -47,51 +47,50 @@
"dependencies": {
"@parcel/source-map": "^2.1.1",
"assert": "^2.1.0",
"ast-matcher": "^1.1.1",
"ast-matcher": "^1.2.0",
"base64-arraybuffer": "^1.0.2",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"console-browserify": "^1.2.0",
"constants-browserify": "^1.0.0",
"convert-source-map": "^1.9.0",
"convert-source-map": "^2.0.0",
"crypto-browserify": "^3.12.0",
"domain-browser": "^5.7.0",
"dumber-module-loader": "^1.2.5",
"eslint-scope": "^8.0.1",
"eslint-scope": "^8.0.2",
"events": "^3.3.0",
"fs-browser-stub": "^1.0.1",
"https-browserify": "^1.0.0",
"meriyah": "^4.4.2",
"meriyah": "^6.0.1",
"modify-code": "^2.1.4",
"node-fetch": "^2.7.0",
"os-browserify": "^0.3.0",
"path-browserify": "1.0.1",
"process": "^0.11.10",
"punycode": "^2.3.1",
"querystring-browser-stub": "^1.0.0",
"readable-stream": "^3.6.0",
"readable-stream": "^3.6.2",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"string_decoder": "^1.3.0",
"timers-browserify": "^2.0.12",
"tslib": "^2.6.2",
"tslib": "^2.7.0",
"tty-browserify": "0.0.1",
"typescript": "^5.4.5",
"url": "^0.11.3",
"typescript": "^5.6.2",
"url": "^0.11.4",
"util": "^0.12.5",
"vm-browserify": "^1.1.2"
},
"devDependencies": {
"browser-do": "^5.0.0",
"c8": "^9.1.0",
"c8": "^10.1.2",
"eslint": "^8.18.0",
"gulp": "^4.0.2",
"gulp-dumber": "^2.0.0",
"lodash": "^4.17.21",
"pta": "^1.2.0",
"semver": "^7.6.2",
"pta": "^1.3.0",
"semver": "^7.6.3",
"sourcemap-codec": "^1.4.8",
"standard-changelog": "^6.0.0",
"zora": "^5.2.0"
"zora": "^6.0.0"
}
}
2 changes: 1 addition & 1 deletion test/bundler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ test('Bundler allows same modules in both user and package space', async t => {
},
{
"path": "src/util.js",
"contents": 'define(\'util.js\',[\'require\',\'exports\',\'module\'],function (require, exports, module) {\n"use strict";\nObject.defineProperty(exports, "__esModule", { value: true });\nfunction default_1() { }\nexports.default = default_1;\n\n});\n'
"contents": 'define(\'util.js\',[\'require\',\'exports\',\'module\'],function (require, exports, module) {\n"use strict";\nObject.defineProperty(exports, "__esModule", { value: true });\nexports.default = default_1;\nfunction default_1() { }\n\n});\n'
},
{
"contents": "define.switchToPackageSpace();"
Expand Down
2 changes: 1 addition & 1 deletion test/package-file-reader/node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ test('defaultNpmPackageFileReader returns fileRead func rejects missing file for

test('defaultNpmPackageFileReader can read .wasm file into base64 string', async t => {
const defaultFileReader = mockPackageFileReader(buildReadFile({
'node_modules/foo/fib.wasm': fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'fib.wasm'))
'node_modules/foo/fib.wasm': fs.readFileSync(path.join(__dirname, '..', '..', 'fixtures', 'fib.wasm'))
}));

return defaultFileReader({name: 'foo'})
Expand Down
6 changes: 3 additions & 3 deletions test/shared.read-source-map.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ const {getSourceMap} = require('../lib/shared');

// no test in browser
test('getSourceMap gets referenced sourceMap file content', t => {
const filePath = path.join('test', 'fixtures', 'y.js');
const filePath = path.join('fixtures', 'y.js');
const contents = fs.readFileSync(filePath, 'utf8');
const sourceMap = getSourceMap(contents, filePath);
t.ok(sourceMap);
t.deepEqual(sourceMap.sources, ['test/fixtures/src/x.js']);
t.deepEqual(sourceMap.sources, ['fixtures/src/x.ts']);
t.ok(sourceMap.sourcesContent);
t.equal(sourceMap.sourcesContent.length, 1);
t.equal(typeof sourceMap.sourcesContent[0], 'string');
t.ok(sourceMap.sourcesContent[0].includes('_.trim'));
});

test('getSourceMap ignores missing sourceMap file', t => {
const filePath = path.join('test', 'fixtures', 'missing.js');
const filePath = path.join('fixtures', 'missing.js');
const contents = fs.readFileSync(filePath, 'utf8');
const sourceMap = getSourceMap(contents, filePath);
t.notOk(sourceMap);
Expand Down
6 changes: 3 additions & 3 deletions test/trace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ test('trace traces npm main in cjs', async t => {
test('trace traces npm main in mjs', async t => {
const unit = {
path: 'node_modules/foo/dist/bar.mjs',
contents: "import a from 'a';",
contents: "import {a} from 'a';a();",
moduleId: 'foo/dist/bar',
packageName: 'foo',
packageMainPath: 'dist/bar.mjs',
Expand All @@ -620,10 +620,10 @@ test('trace traces npm main in mjs', async t => {
return trace(unit).then(traced => {
t.deepEqual(traced, {
path: 'node_modules/foo/dist/bar.mjs',
contents: 'define(\'foo/dist/bar\',[\'require\',\'exports\',\'module\',\'tslib\',\'a\'],function (require, exports, module) {\n"use strict";\nObject.defineProperty(exports, "__esModule", { value: true });\nconst tslib_1 = require("tslib");\nconst a_1 = tslib_1.__importDefault(require("a"));\n\n});\n\n;define.alias(\'foo\',\'foo/dist/bar\');',
contents: "define('foo/dist/bar',['require','exports','module','a'],function (require, exports, module) {\n\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst a_1 = require(\"a\");\n(0, a_1.a)();\n\n});\n\n;define.alias('foo','foo/dist/bar');",
moduleId: 'foo/dist/bar',
defined: ['foo/dist/bar', 'foo'],
deps: ['tslib', 'a'],
deps: ['a'],
packageName: 'foo',
packageMainPath: 'dist/bar.mjs',
alias: null,
Expand Down
32 changes: 17 additions & 15 deletions test/transformers/esm-to-cjs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,22 @@ test('esm uses file name in existing sourcemap', t => {
t.ok(newUnit.forceWrap);
});

test('esm supports dynamic import() in ES module', t => {
const unit = {
contents: 'export default import("./a");',
path: 'src/file.js',
moduleId: 'file'
};
const newUnit = esm(unit);
t.ok(newUnit.contents.includes('__esModule'));
t.ok(newUnit.contents.includes('import('));
t.deepEqual(newUnit.sourceMap.sources, ['src/file.js']);
t.equal(newUnit.sourceMap.file, 'src/file.js');
t.ok(newUnit.sourceMap.mappings);
t.ok(newUnit.forceWrap);
});
// Latest TypeScript does compile import() in to wrapped cjs require()
// test('esm supports dynamic import() in ES module', t => {
// const unit = {
// contents: 'export default import("./a");',
// path: 'src/file.js',
// moduleId: 'file'
// };
// const newUnit = esm(unit);
// console.log('###' + newUnit.contents);
// t.ok(newUnit.contents.includes('__esModule'));
// t.ok(newUnit.contents.includes('import('));
// t.deepEqual(newUnit.sourceMap.sources, ['src/file.js']);
// t.equal(newUnit.sourceMap.file, 'src/file.js');
// t.ok(newUnit.sourceMap.mappings);
// t.ok(newUnit.forceWrap);
// });

test('esm does not transpile latest es syntax', t => {
const unit = {
Expand All @@ -79,7 +81,7 @@ test('esm does not transpile latest es syntax', t => {
moduleId: 'file'
};
const newUnit = esm(unit);
t.equal(newUnit.contents, '"use strict";\nObject.defineProperty(exports, "__esModule", { value: true });\nexports.foo = void 0;\nasync function* foo(a) { yield a?.b; }\nexports.foo = foo;\n');
t.equal(newUnit.contents, '"use strict";\nObject.defineProperty(exports, "__esModule", { value: true });\nexports.foo = foo;\nasync function* foo(a) { yield a?.b; }\n');
t.deepEqual(newUnit.sourceMap.sources, ['src/file.js']);
t.equal(newUnit.sourceMap.file, 'src/file.js');
t.ok(newUnit.sourceMap.mappings);
Expand Down

0 comments on commit c723de6

Please sign in to comment.