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

Replace ava with uvu #938

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .github/workflows/size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: yarn install
- run: yarn build
- run: yarn size
58 changes: 1 addition & 57 deletions config/rollup.main-thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

import compiler from '@ampproject/rollup-plugin-closure-compiler';
import { terser } from 'rollup-plugin-terser';
import replace from '@rollup/plugin-replace';
import { babelPlugin, removeDebugCommandExecutors, removeWorkerWhitespace } from './rollup.plugins.js';

Expand All @@ -34,11 +32,8 @@ const ESModules = [
WORKER_DOM_DEBUG: false,
}),
babelPlugin({
transpileToES5: false,
allowConsole: false,
}),
compiler(),
terser(),
],
},
{
Expand All @@ -54,7 +49,6 @@ const ESModules = [
WORKER_DOM_DEBUG: true,
}),
babelPlugin({
transpileToES5: false,
allowConsole: true,
}),
],
Expand All @@ -73,11 +67,8 @@ const ESModules = [
WORKER_DOM_DEBUG: false,
}),
babelPlugin({
transpileToES5: false,
allowConsole: false,
}),
compiler(),
terser(),
],
},
{
Expand All @@ -93,57 +84,10 @@ const ESModules = [
WORKER_DOM_DEBUG: true,
}),
babelPlugin({
transpileToES5: false,
allowConsole: true,
}),
],
},
];

const IIFEModules = [
{
input: 'output/main-thread/index.js',
output: {
file: 'dist/main.js',
format: 'iife',
name: 'MainThread',
sourcemap: true,
},
plugins: [
removeWorkerWhitespace(),
removeDebugCommandExecutors(),
replace({
WORKER_DOM_DEBUG: false,
}),
babelPlugin({
transpileToES5: true,
allowConsole: false,
}),
compiler(),
terser(),
],
},
{
input: 'output/main-thread/index.js',
output: {
file: 'dist/debug/main.js',
format: 'iife',
name: 'MainThread',
sourcemap: true,
},
plugins: [
removeWorkerWhitespace(),
replace({
WORKER_DOM_DEBUG: true,
}),
babelPlugin({
transpileToES5: true,
allowConsole: true,
}),
compiler(),
terser(),
],
},
];

export default [...ESModules, ...IIFEModules];
export default [...ESModules];
37 changes: 4 additions & 33 deletions config/rollup.plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import babel from 'rollup-plugin-babel';
import babel from '@rollup/plugin-babel';
import MagicString from 'magic-string';
import fs from 'fs';
import * as path from 'path';
Expand All @@ -27,42 +27,13 @@ const walk = require('acorn-walk');
* - allowConsole Should we allow `console` methods in the output?
* - allowPostMessage Should we allow postMessage to/from the Worker?
*/
export function babelPlugin({ transpileToES5, allowConsole = false, allowPostMessage = true }) {
const targets = transpileToES5 ? { browsers: ['last 2 versions', 'ie >= 11', 'safari >= 7'] } : { esmodules: true };
export function babelPlugin({ allowConsole = false }) {
const exclude = allowConsole ? ['error', 'warn', 'trace', 'info', 'log', 'time', 'timeEnd'] : [];

return babel({
exclude: 'node_modules/**',
presets: [
[
'@babel/env',
{
targets,
loose: !transpileToES5,
modules: false,
bugfixes: true,
},
],
],
plugins: [
['@babel/plugin-proposal-object-rest-spread'],
['@babel/proposal-class-properties'],
[
'babel-plugin-minify-replace',
{
replacements: [
{
identifierName: '__ALLOW_POST_MESSAGE__',
replacement: {
type: 'booleanLiteral',
value: allowPostMessage,
},
},
],
},
],
['babel-plugin-transform-remove-console', { exclude }],
],
babelHelpers: 'bundled',
plugins: [['babel-plugin-transform-remove-console', { exclude }]],
});
}

Expand Down
135 changes: 1 addition & 134 deletions config/rollup.worker-thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,9 @@
* limitations under the License.
*/

import compiler from '@ampproject/rollup-plugin-closure-compiler';
import { terser } from 'rollup-plugin-terser';
import replace from '@rollup/plugin-replace';
import { babelPlugin } from './rollup.plugins.js';

// Compile plugins should always be added at the end of the plugin list.
const compilePlugins = [
compiler({
env: 'CUSTOM',
}),
terser(),
];

// Workers do not natively support ES Modules containing `import` or `export` statments.
// So, here we continue to use the '.mjs' extension to indicate newer ECMASCRIPT support
// but ensure the code can be run within a worker by putting it inside a named iife.
Expand All @@ -44,10 +34,8 @@ const ESModules = [
WORKER_DOM_DEBUG: false,
}),
babelPlugin({
transpileToES5: false,
allowConsole: false,
}),
...compilePlugins,
],
},
{
Expand All @@ -63,7 +51,6 @@ const ESModules = [
WORKER_DOM_DEBUG: true,
}),
babelPlugin({
transpileToES5: false,
allowConsole: true,
}),
],
Expand All @@ -81,10 +68,8 @@ const ESModules = [
WORKER_DOM_DEBUG: false,
}),
babelPlugin({
transpileToES5: false,
allowConsole: false,
}),
...compilePlugins,
],
},
{
Expand All @@ -97,44 +82,6 @@ const ESModules = [
},
plugins: [
babelPlugin({
transpileToES5: false,
allowConsole: true,
}),
],
},
{
input: 'output/worker-thread/index.amp.js',
output: {
file: 'dist/amp-production/worker/worker.js',
format: 'iife',
name: 'WorkerThread',
sourcemap: true,
},
plugins: [
replace({
WORKER_DOM_DEBUG: false,
}),
babelPlugin({
transpileToES5: true,
allowConsole: false,
}),
...compilePlugins,
],
},
{
input: 'output/worker-thread/index.amp.js',
output: {
file: 'dist/amp-debug/worker/worker.js',
format: 'iife',
name: 'WorkerThread',
sourcemap: true,
},
plugins: [
replace({
WORKER_DOM_DEBUG: true,
}),
babelPlugin({
transpileToES5: true,
allowConsole: true,
}),
],
Expand All @@ -152,10 +99,8 @@ const ESModules = [
WORKER_DOM_DEBUG: false,
}),
babelPlugin({
transpileToES5: false,
allowConsole: true,
}),
...compilePlugins,
],
},
{
Expand All @@ -171,88 +116,10 @@ const ESModules = [
WORKER_DOM_DEBUG: true,
}),
babelPlugin({
transpileToES5: false,
allowConsole: true,
}),
],
},
{
input: 'output/worker-thread/index.nodom.amp.js',
output: {
file: 'dist/amp-production/worker/worker.nodom.js',
format: 'iife',
name: 'WorkerThread',
sourcemap: true,
},
plugins: [
replace({
WORKER_DOM_DEBUG: false,
}),
babelPlugin({
transpileToES5: true,
allowConsole: false,
}),
...compilePlugins,
],
},
{
input: 'output/worker-thread/index.nodom.amp.js',
output: {
file: 'dist/amp-debug/worker/worker.nodom.js',
format: 'iife',
name: 'WorkerThread',
sourcemap: true,
},
plugins: [
replace({
WORKER_DOM_DEBUG: true,
}),
babelPlugin({
transpileToES5: true,
allowConsole: true,
}),
],
},
];

const IIFEModules = [
{
input: 'output/worker-thread/index.js',
output: {
file: 'dist/worker/worker.js',
format: 'iife',
name: 'WorkerThread',
sourcemap: true,
},
plugins: [
replace({
WORKER_DOM_DEBUG: false,
}),
babelPlugin({
transpileToES5: true,
allowConsole: false,
}),
...compilePlugins,
],
},
{
input: 'output/worker-thread/index.js',
output: {
file: 'dist/debug/worker/worker.js',
format: 'iife',
name: 'WorkerThread',
sourcemap: true,
},
plugins: [
replace({
WORKER_DOM_DEBUG: true,
}),
babelPlugin({
transpileToES5: true,
allowConsole: true,
}),
],
},
];

export default [...ESModules, ...IIFEModules];
export default [...ESModules];
12 changes: 7 additions & 5 deletions demo/call-function/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<title>Call function</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="/dist/amp/main.mjs" type="module"></script>
<script src="/dist/amp-production/main.mjs" type="module"></script>
</head>
<body>
<div src="call-function.js" id="upgrade-me"></div>
Expand All @@ -19,7 +19,9 @@
.then((result) => console.log(`Complex math result: ${result}`));
worker
.callFunction("getRemoteData")
.then((result) => console.log(`Remote data: ${JSON.stringify(result)}`));
.then((result) =>
console.log(`Remote data: ${JSON.stringify(result)}`)
);

const addResult = await worker.callFunction("add", 40, 2);
console.log(`Answer to it all: ${addResult}`);
Expand All @@ -30,9 +32,9 @@
console.log(`concat([1,2,3], ["4", "5"]) is: ${result}`)
);

worker.callFunction('returnsUndefined').then(result => {
console.log(`undefined --> ${result}`)
})
worker.callFunction("returnsUndefined").then((result) => {
console.log(`undefined --> ${result}`);
});

worker.callFunction("reject").catch((err) => console.error(err));
worker
Expand Down
Loading