Skip to content

Commit 6738599

Browse files
⬆️ deps: Upgrade ava to v4.0.0-rc.1.
1 parent ccdf60b commit 6738599

File tree

9 files changed

+372
-358
lines changed

9 files changed

+372
-358
lines changed

package.json

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,20 @@
6868
"prepare": "npm run build",
6969
"prepublishOnly": "pinst --disable",
7070
"release": "np --message ':hatching_chick: release: Bumping to v%s.'",
71-
"test": "ava"
71+
"test": "npm run test:src",
72+
"test-cmd": "NODE_LOADER_CONFIG=test/loader/config.js ava",
73+
"test:cjs": "IMPORT_MAP_PATH=test/import-maps/dist/index.json npm run test-cmd",
74+
"test:dist": "npm run test:modern && npm run test:module && npm run test:cjs",
75+
"test:modern": "IMPORT_MAP_PATH=test/import-maps/dist/index.modern.json npm run test-cmd",
76+
"test:module": "IMPORT_MAP_PATH=test/import-maps/dist/index.module.json npm run test-cmd",
77+
"test:src": "IMPORT_MAP_PATH=test/import-maps/src/index.json npm run test-cmd"
7278
},
7379
"dependencies": {
7480
"@combinatorics/permutation": "^4.0.0"
7581
},
7682
"devDependencies": {
7783
"@babel/core": "7.16.5",
7884
"@babel/preset-env": "7.16.5",
79-
"@babel/register": "7.16.5",
8085
"@commitlint/cli": "15.0.0",
8186
"@iterable-iterator/list": "1.0.1",
8287
"@iterable-iterator/map": "1.0.1",
@@ -86,10 +91,13 @@
8691
"@iterable-iterator/sorted": "1.0.0",
8792
"@iterable-iterator/zip": "1.0.1",
8893
"@js-library/commitlint-config": "0.0.4",
94+
"@node-loader/babel": "2.0.0",
95+
"@node-loader/core": "2.0.0",
96+
"@node-loader/import-maps": "1.0.3",
8997
"@randomized/random": "4.0.0",
9098
"@total-order/lex": "1.0.0",
9199
"@total-order/primitive": "1.0.1",
92-
"ava": "3.15.0",
100+
"ava": "4.0.0-rc.1",
93101
"babel-plugin-transform-remove-console": "6.9.4",
94102
"babel-plugin-unassert": "3.2.0",
95103
"babel-preset-power-assert": "3.0.0",
@@ -113,21 +121,15 @@
113121
"test/src/**/*"
114122
],
115123
"require": [
116-
"regenerator-runtime/runtime",
117-
"@babel/register"
124+
"regenerator-runtime/runtime"
125+
],
126+
"nodeArguments": [
127+
"--experimental-loader=@node-loader/core"
118128
],
119129
"timeout": "1m"
120130
},
121131
"babel": {
122132
"sourceMaps": true,
123-
"presets": [
124-
[
125-
"@babel/preset-env",
126-
{
127-
"targets": "current node"
128-
}
129-
]
130-
],
131133
"plugins": [
132134
[
133135
"transform-remove-console",

test/import-maps/dist/index.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"imports": {
3+
"#module": "./dist/index.cjs"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"imports": {
3+
"#module": "./dist/index.modern.js"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"imports": {
3+
"#module": "./dist/index.module.js"
4+
}
5+
}

test/import-maps/src/index.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"imports": {
3+
"#module": "./src/index.js"
4+
}
5+
}

test/loader/babel.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* Based on source of @node-loader/babel
3+
*
4+
* Source: https://github.com/node-loader/node-loader-babel
5+
*
6+
* with the following license:
7+
*
8+
* MIT License
9+
*
10+
* Copyright (c) 2020 node-loaders
11+
*
12+
* Permission is hereby granted, free of charge, to any person obtaining a copy
13+
* of this software and associated documentation files (the "Software"), to deal
14+
* in the Software without restriction, including without limitation the rights
15+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
* copies of the Software, and to permit persons to whom the Software is
17+
* furnished to do so, subject to the following conditions:
18+
*
19+
* The above copyright notice and this permission notice shall be included in all
20+
* copies or substantial portions of the Software.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28+
* SOFTWARE.
29+
*/
30+
31+
import process from 'process';
32+
import path from 'path';
33+
import {fileURLToPath} from 'url';
34+
import {loadOptionsAsync, transformAsync} from '@babel/core';
35+
36+
const BABEL_FORMATS_TRANSFORMED = new Set(['module']);
37+
38+
const BABEL_CONFIG_FILES = new Set([
39+
'.babelrc.js',
40+
'.babelrc.mjs',
41+
'babel.config.js',
42+
'babel.config.mjs',
43+
'.babelrc',
44+
'.babelrc.cjs',
45+
'babel.config.cjs',
46+
]);
47+
48+
const anyURLToPathOrUndefined = (url) => {
49+
try {
50+
return fileURLToPath(url);
51+
} catch (error) {
52+
if (error instanceof TypeError && error.code === 'ERR_INVALID_URL_SCHEME') {
53+
return undefined;
54+
}
55+
56+
throw error;
57+
}
58+
};
59+
60+
const isBabelConfigFile = (filename) => {
61+
const basename = path.basename(filename);
62+
return BABEL_CONFIG_FILES.has(basename);
63+
};
64+
65+
const getSourceType = (format) => {
66+
switch (format) {
67+
case 'module':
68+
return 'module';
69+
case 'commonjs':
70+
return 'script';
71+
default:
72+
return 'unambiguous';
73+
}
74+
};
75+
76+
const prepare = async (url, context, defaultLoad) => {
77+
const original = await defaultLoad(url, context, defaultLoad);
78+
79+
const noop = () => ({
80+
transform: false,
81+
original,
82+
});
83+
84+
if (
85+
/node_modules/.test(url) ||
86+
/node:/.test(url) ||
87+
!BABEL_FORMATS_TRANSFORMED.has(original.format)
88+
) {
89+
return noop();
90+
}
91+
92+
const filename = anyURLToPathOrUndefined(url);
93+
94+
// Babel config files can themselves be ES modules,
95+
// but transforming those could require more than one pass.
96+
if (isBabelConfigFile(filename)) return noop();
97+
98+
return {
99+
transform: true,
100+
original,
101+
options: {
102+
filename,
103+
},
104+
};
105+
};
106+
107+
const transformed = async ({format, source}, {filename}) => {
108+
const options = await loadOptionsAsync({
109+
sourceType: getSourceType(format),
110+
root: process.cwd(),
111+
rootMode: 'root',
112+
filename,
113+
configFile: true,
114+
});
115+
116+
const result = await transformAsync(source, options);
117+
118+
return {
119+
source: result.code,
120+
// TODO: look at babel config to see whether it will output ESM/CJS or other formats
121+
format,
122+
};
123+
};
124+
125+
export const load = async (url, context, defaultLoad) => {
126+
const {transform, original, options} = await prepare(
127+
url,
128+
context,
129+
defaultLoad,
130+
);
131+
return transform ? transformed(original, options) : original;
132+
};

test/loader/config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as importMapLoader from '@node-loader/import-maps';
2+
// Import * as babelLoader from "@node-loader/babel";
3+
import * as babelLoader from './babel.js';
4+
5+
const config = {
6+
loaders: [importMapLoader, babelLoader],
7+
};
8+
9+
export default config;

test/src/api/sort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {AssertionError} from 'assert';
1+
import assert from 'assert';
22
import test from 'ava';
33
import {list} from '@iterable-iterator/list';
44
import {all} from '@iterable-iterator/reduce';
@@ -24,7 +24,7 @@ limbs.title = (title, k, M, data) =>
2424
title || `sort(${k}, ${M}, ${JSON.stringify(data)})`;
2525

2626
const throws = (t, k, M, data) => {
27-
t.throws(() => sort(k, M, data.slice()), {instanceOf: AssertionError});
27+
t.throws(() => sort(k, M, data.slice()), {instanceOf: assert.AssertionError});
2828
};
2929

3030
throws.title = (title, k, M, data) =>

0 commit comments

Comments
 (0)