Skip to content

Commit

Permalink
⬆️ deps: Upgrade ava to v4.0.0-rc.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Dec 24, 2021
1 parent ccdf60b commit 6738599
Show file tree
Hide file tree
Showing 9 changed files with 372 additions and 358 deletions.
28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,20 @@
"prepare": "npm run build",
"prepublishOnly": "pinst --disable",
"release": "np --message ':hatching_chick: release: Bumping to v%s.'",
"test": "ava"
"test": "npm run test:src",
"test-cmd": "NODE_LOADER_CONFIG=test/loader/config.js ava",
"test:cjs": "IMPORT_MAP_PATH=test/import-maps/dist/index.json npm run test-cmd",
"test:dist": "npm run test:modern && npm run test:module && npm run test:cjs",
"test:modern": "IMPORT_MAP_PATH=test/import-maps/dist/index.modern.json npm run test-cmd",
"test:module": "IMPORT_MAP_PATH=test/import-maps/dist/index.module.json npm run test-cmd",
"test:src": "IMPORT_MAP_PATH=test/import-maps/src/index.json npm run test-cmd"
},
"dependencies": {
"@combinatorics/permutation": "^4.0.0"
},
"devDependencies": {
"@babel/core": "7.16.5",
"@babel/preset-env": "7.16.5",
"@babel/register": "7.16.5",
"@commitlint/cli": "15.0.0",
"@iterable-iterator/list": "1.0.1",
"@iterable-iterator/map": "1.0.1",
Expand All @@ -86,10 +91,13 @@
"@iterable-iterator/sorted": "1.0.0",
"@iterable-iterator/zip": "1.0.1",
"@js-library/commitlint-config": "0.0.4",
"@node-loader/babel": "2.0.0",
"@node-loader/core": "2.0.0",
"@node-loader/import-maps": "1.0.3",
"@randomized/random": "4.0.0",
"@total-order/lex": "1.0.0",
"@total-order/primitive": "1.0.1",
"ava": "3.15.0",
"ava": "4.0.0-rc.1",
"babel-plugin-transform-remove-console": "6.9.4",
"babel-plugin-unassert": "3.2.0",
"babel-preset-power-assert": "3.0.0",
Expand All @@ -113,21 +121,15 @@
"test/src/**/*"
],
"require": [
"regenerator-runtime/runtime",
"@babel/register"
"regenerator-runtime/runtime"
],
"nodeArguments": [
"--experimental-loader=@node-loader/core"
],
"timeout": "1m"
},
"babel": {
"sourceMaps": true,
"presets": [
[
"@babel/preset-env",
{
"targets": "current node"
}
]
],
"plugins": [
[
"transform-remove-console",
Expand Down
5 changes: 5 additions & 0 deletions test/import-maps/dist/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"#module": "./dist/index.cjs"
}
}
5 changes: 5 additions & 0 deletions test/import-maps/dist/index.modern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"#module": "./dist/index.modern.js"
}
}
5 changes: 5 additions & 0 deletions test/import-maps/dist/index.module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"#module": "./dist/index.module.js"
}
}
5 changes: 5 additions & 0 deletions test/import-maps/src/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"#module": "./src/index.js"
}
}
132 changes: 132 additions & 0 deletions test/loader/babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* Based on source of @node-loader/babel
*
* Source: https://github.com/node-loader/node-loader-babel
*
* with the following license:
*
* MIT License
*
* Copyright (c) 2020 node-loaders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import process from 'process';
import path from 'path';
import {fileURLToPath} from 'url';
import {loadOptionsAsync, transformAsync} from '@babel/core';

const BABEL_FORMATS_TRANSFORMED = new Set(['module']);

const BABEL_CONFIG_FILES = new Set([
'.babelrc.js',
'.babelrc.mjs',
'babel.config.js',
'babel.config.mjs',
'.babelrc',
'.babelrc.cjs',
'babel.config.cjs',
]);

const anyURLToPathOrUndefined = (url) => {
try {
return fileURLToPath(url);
} catch (error) {
if (error instanceof TypeError && error.code === 'ERR_INVALID_URL_SCHEME') {
return undefined;
}

throw error;
}
};

const isBabelConfigFile = (filename) => {
const basename = path.basename(filename);
return BABEL_CONFIG_FILES.has(basename);
};

const getSourceType = (format) => {
switch (format) {
case 'module':
return 'module';
case 'commonjs':
return 'script';
default:
return 'unambiguous';
}
};

const prepare = async (url, context, defaultLoad) => {
const original = await defaultLoad(url, context, defaultLoad);

const noop = () => ({
transform: false,
original,
});

if (
/node_modules/.test(url) ||
/node:/.test(url) ||
!BABEL_FORMATS_TRANSFORMED.has(original.format)
) {
return noop();
}

const filename = anyURLToPathOrUndefined(url);

// Babel config files can themselves be ES modules,
// but transforming those could require more than one pass.
if (isBabelConfigFile(filename)) return noop();

return {
transform: true,
original,
options: {
filename,
},
};
};

const transformed = async ({format, source}, {filename}) => {
const options = await loadOptionsAsync({
sourceType: getSourceType(format),
root: process.cwd(),
rootMode: 'root',
filename,
configFile: true,
});

const result = await transformAsync(source, options);

return {
source: result.code,
// TODO: look at babel config to see whether it will output ESM/CJS or other formats
format,
};
};

export const load = async (url, context, defaultLoad) => {
const {transform, original, options} = await prepare(
url,
context,
defaultLoad,
);
return transform ? transformed(original, options) : original;
};
9 changes: 9 additions & 0 deletions test/loader/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as importMapLoader from '@node-loader/import-maps';
// Import * as babelLoader from "@node-loader/babel";
import * as babelLoader from './babel.js';

const config = {
loaders: [importMapLoader, babelLoader],
};

export default config;
4 changes: 2 additions & 2 deletions test/src/api/sort.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AssertionError} from 'assert';
import assert from 'assert';
import test from 'ava';
import {list} from '@iterable-iterator/list';
import {all} from '@iterable-iterator/reduce';
Expand All @@ -24,7 +24,7 @@ limbs.title = (title, k, M, data) =>
title || `sort(${k}, ${M}, ${JSON.stringify(data)})`;

const throws = (t, k, M, data) => {
t.throws(() => sort(k, M, data.slice()), {instanceOf: AssertionError});
t.throws(() => sort(k, M, data.slice()), {instanceOf: assert.AssertionError});
};

throws.title = (title, k, M, data) =>
Expand Down
Loading

0 comments on commit 6738599

Please sign in to comment.