Skip to content

Commit

Permalink
Convert project to entirely es modules (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewiggins committed Oct 16, 2023
1 parent df57dd0 commit a3e8a79
Show file tree
Hide file tree
Showing 25 changed files with 62 additions and 52 deletions.
16 changes: 8 additions & 8 deletions frameworks/bundleHelpers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const path = require("path");
const { readdirSync, existsSync } = require("fs");
const nodeResolve = require("@rollup/plugin-node-resolve").default;
const { default: terser } = require("@rollup/plugin-terser");
const visualizer = require("rollup-plugin-visualizer").default;
import path from "path";
import { readdirSync, existsSync } from "fs";
import nodeResolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import { visualizer } from "rollup-plugin-visualizer";

const __dirname = new URL(".", import.meta.url).pathname;

const frameworkOutput = (...args) =>
path.join(__dirname, "../dist/frameworks", ...args);
Expand All @@ -16,7 +18,7 @@ const listDirsSync = source =>
* @param {string} frameworkName
* @param {(environment: Environment) => any[]} plugins
*/
function generateConfigs(frameworkName, plugins) {
export function generateConfigs(frameworkName, plugins) {
return listDirsSync("./src")
.map(appFolder => {
const jsIndexPath = `./src/${appFolder}/index.js`;
Expand Down Expand Up @@ -86,5 +88,3 @@ function generateConfig(
}
};
}

module.exports = { generateConfigs };
1 change: 1 addition & 0 deletions frameworks/lit-html/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "lit-html-apps",
"type": "module",
"private": true,
"version": "0.0.1",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions frameworks/lit-html/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const { generateConfigs } = require("../bundleHelpers");
import { generateConfigs } from "../bundleHelpers.js";

module.exports = generateConfigs("lit-html", () => []);
export default generateConfigs("lit-html", () => []);
1 change: 1 addition & 0 deletions frameworks/preact-hooks/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "preact-hooks-apps",
"type": "module",
"private": true,
"version": "0.0.1",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions frameworks/preact-hooks/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const babel = require("@rollup/plugin-babel").default;
const { generateConfigs } = require("../bundleHelpers");
import babel from "@rollup/plugin-babel";
import { generateConfigs } from "../bundleHelpers.js";

const plugins = () => [
babel({
Expand All @@ -8,4 +8,4 @@ const plugins = () => [
})
];

module.exports = generateConfigs("preact-hooks", plugins);
export default generateConfigs("preact-hooks", plugins);
1 change: 1 addition & 0 deletions frameworks/preact/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "preact-apps",
"type": "module",
"private": true,
"version": "0.0.1",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions frameworks/preact/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const babel = require("@rollup/plugin-babel").default;
const { generateConfigs } = require("../bundleHelpers");
import babel from "@rollup/plugin-babel";
import { generateConfigs } from "../bundleHelpers.js";

const plugins = () => [
babel({
Expand All @@ -8,4 +8,4 @@ const plugins = () => [
})
];

module.exports = generateConfigs("preact", plugins);
export default generateConfigs("preact", plugins);
1 change: 1 addition & 0 deletions frameworks/react-hooks/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "react-hooks-apps",
"type": "module",
"private": true,
"version": "0.0.1",
"license": "MIT",
Expand Down
10 changes: 5 additions & 5 deletions frameworks/react-hooks/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const babel = require("@rollup/plugin-babel").default;
const replace = require("@rollup/plugin-replace");
const commonjs = require("@rollup/plugin-commonjs");
const { generateConfigs } = require("../bundleHelpers");
import babel from "@rollup/plugin-babel";
import replace from "@rollup/plugin-replace";
import commonjs from "@rollup/plugin-commonjs";
import { generateConfigs } from "../bundleHelpers.js";

const plugins = environment => [
babel({
Expand All @@ -19,4 +19,4 @@ const plugins = environment => [
commonjs()
];

module.exports = generateConfigs("react-hooks", plugins);
export default generateConfigs("react-hooks", plugins);
1 change: 1 addition & 0 deletions frameworks/react/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "react-apps",
"type": "module",
"private": true,
"version": "0.0.1",
"license": "MIT",
Expand Down
10 changes: 5 additions & 5 deletions frameworks/react/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const babel = require("@rollup/plugin-babel").default;
const replace = require("@rollup/plugin-replace");
const commonjs = require("@rollup/plugin-commonjs");
const { generateConfigs } = require("../bundleHelpers");
import babel from "@rollup/plugin-babel";
import replace from "@rollup/plugin-replace";
import commonjs from "@rollup/plugin-commonjs";
import { generateConfigs } from "../bundleHelpers.js";

const plugins = environment => [
babel({
Expand All @@ -19,4 +19,4 @@ const plugins = environment => [
commonjs()
];

module.exports = generateConfigs("react", plugins);
export default generateConfigs("react", plugins);
1 change: 1 addition & 0 deletions frameworks/solid-js/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "solid-js-apps",
"type": "module",
"private": true,
"version": "0.0.1",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions frameworks/solid-js/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const babel = require("@rollup/plugin-babel").default;
const { generateConfigs } = require("../bundleHelpers");
import babel from "@rollup/plugin-babel";
import { generateConfigs } from "../bundleHelpers.js";

const plugins = () => [
babel({
babelHelpers: "bundled"
})
];

module.exports = generateConfigs("solid-js", plugins);
export default generateConfigs("solid-js", plugins);
4 changes: 2 additions & 2 deletions frameworks/svelte/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Use babel.config.js to override local .babelrc in Svelte
module.exports = function (api) {
export default function (api) {
api.cache(true);

return {
Expand All @@ -13,4 +13,4 @@ module.exports = function (api) {
]
]
};
};
}
1 change: 1 addition & 0 deletions frameworks/svelte/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "svelte-apps",
"type": "module",
"private": true,
"version": "0.0.1",
"license": "MIT",
Expand Down
11 changes: 5 additions & 6 deletions frameworks/svelte/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const { DEFAULT_EXTENSIONS } = require("@babel/core");
const svelte = require("rollup-plugin-svelte");
const babel = require("@rollup/plugin-babel").default;
const { generateConfigs } = require("../bundleHelpers");
import { DEFAULT_EXTENSIONS } from "@babel/core";
import svelte from "rollup-plugin-svelte";
import babel from "@rollup/plugin-babel";
import { generateConfigs } from "../bundleHelpers.js";

const plugins = () => [
// @ts-expect-error Bad mixing of COMMONJS and ESM
svelte({
extensions: [".html"]
}),
Expand All @@ -14,4 +13,4 @@ const plugins = () => [
})
];

module.exports = generateConfigs("svelte", plugins);
export default generateConfigs("svelte", plugins);
1 change: 1 addition & 0 deletions frameworks/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "vue-apps",
"type": "module",
"private": true,
"version": "0.0.1",
"license": "MIT",
Expand Down
10 changes: 5 additions & 5 deletions frameworks/vue/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const replace = require("@rollup/plugin-replace");
const commonjs = require("@rollup/plugin-commonjs");
const vue = require("rollup-plugin-vue");
const { generateConfigs } = require("../bundleHelpers");
import replace from "@rollup/plugin-replace";
import commonjs from "@rollup/plugin-commonjs";
import vue from "rollup-plugin-vue";
import { generateConfigs } from "../bundleHelpers.js";

// Guide to setting up bundler:
// https://github.com/vuejs/vue-next/tree/master/packages/vue#bundler-build-feature-flags

module.exports = generateConfigs("vue", environment => [
export default generateConfigs("vue", environment => [
// @ts-ignore
vue(),
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const isDebug = process.env.PPTR_DEBUG === "true";

module.exports = {
export default {
launch: {
headless: isDebug ? false : "new",
devtools: isDebug
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "framework-compare",
"type": "module",
"version": "0.0.1",
"private": true,
"description": "Compare implementations of some basic webpages in different frameworks",
Expand Down Expand Up @@ -55,7 +56,7 @@
"puppeteer": "^21.0.3",
"rimraf": "^5.0.1",
"rollup": "^3.28.0",
"rollup-plugin-visualizer": "^5.9.0"
"rollup-plugin-visualizer": "^5.9.2"
},
"jest": {
"preset": "jest-puppeteer",
Expand Down
2 changes: 1 addition & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "scripts",
"type": "module",
"private": true,
"version": "0.0.1",
"license": "MIT",
"type": "module",
"scripts": {
"tsc": "tsc -p jsconfig.json --noEmit"
},
Expand Down
8 changes: 4 additions & 4 deletions sizes.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@
"brotli": 2736
},
"7GUIs-flight-booker": {
"raw": 24511,
"minified": 10295,
"gzip": 4085,
"brotli": 3669
"raw": 24422,
"minified": 10265,
"gzip": 4078,
"brotli": 3662
},
"7GUIs-timer": {
"raw": 19713,
Expand Down
4 changes: 2 additions & 2 deletions tests/babelTransformer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const babelJest = require("babel-jest");
import { createTransformer } from "babel-jest";

// By default, babel-jest looks for a babel.config.js to determine the configuration
// to use to run tests. We don't want to add a babel.config.js at the root of this project
Expand All @@ -8,7 +8,7 @@ const babelJest = require("babel-jest");
// files which didn't intuitively work (specifically the date.test.js file cuz it imports a file
// outside of the "tests" directory where we could put a babel config), we are manually specifying
// a Babel config here
module.exports = babelJest.createTransformer({
export default createTransformer({
presets: [
[
"@babel/preset-env",
Expand Down
1 change: 1 addition & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "tests",
"type": "module",
"version": "1.0.0",
"private": true,
"scripts": {
Expand Down

0 comments on commit a3e8a79

Please sign in to comment.