Skip to content

Commit

Permalink
Move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Dec 20, 2024
1 parent a8b2b4f commit bb59083
Show file tree
Hide file tree
Showing 49 changed files with 970 additions and 1,092 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bundlesize:
./node_modules/.bin/bundlesize

bundle:
node bundle.js
node bundle.cjs

size:
make bundle
Expand Down
43 changes: 22 additions & 21 deletions ava.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
export default {
babel: {
testOptions: {
babelrc: false,
plugins: [
[
"@babel/plugin-transform-react-jsx",
{
pragma: "xml",
throwIfNamespace: false,
},
],
[
"babel-plugin-jsx-pragmatic",
{
module: "@xmpp/xml",
import: "xml",
},
],
],
},
},
// babel: {
// testOptions: {
// babelrc: false,
// plugins: [
// [
// "@babel/plugin-transform-react-jsx",
// {
// pragma: "xml",
// throwIfNamespace: false,
// },
// ],
// [
// "babel-plugin-jsx-pragmatic",
// {
// module: "@xmpp/xml",
// import: "xml",
// },
// ],
// ],
// },
// },
// nodeArguments: ["--loader=babel-register-esm"],
files: [
"packages/**/test.js",
"packages/**/test/*.js",
Expand Down
33 changes: 33 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = {
presets: [
[
"@babel/preset-env",
{
targets: {
ie: "11",
},
loose: true,
},
],
],
plugins: [
"@babel/plugin-transform-runtime",
"babel-plugin-transform-async-to-promises",
"@babel/plugin-proposal-object-rest-spread",

// [
// "@babel/plugin-transform-react-jsx",
// {
// pragma: "xml",
// throwIfNamespace: false,
// },
// ],
// [
// "babel-plugin-jsx-pragmatic",
// {
// module: "@xmpp/xml",
// import: "xml",
// },
// ],
],
};
20 changes: 0 additions & 20 deletions babel.config.js

This file was deleted.

45 changes: 45 additions & 0 deletions bundle.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env node

/* eslint-disable no-console */

"use strict";

const fs = require("fs");
const path = require("path");
const browserify = require("browserify");
const commonShake = require("common-shakeify");
const packFlat = require("browser-pack-flat");
const exorcist = require("exorcist");
const { minify } = require("uglify-js");

const dist = path.join(__dirname, "packages/client/dist");

browserify(path.join(__dirname, "packages/client/"), {
debug: true,
standalone: "XMPP",
})
.transform("babelify", { global: true })
.plugin(commonShake)
.plugin(packFlat)
// .on('dep', dep => {
// console.log(dep.file)
// })
.bundle()
.pipe(exorcist(path.join(dist, "xmpp.js.map")))
.pipe(fs.createWriteStream(path.join(dist, "xmpp.js")))
.on("finish", () => {
const bundled = fs.readFileSync(path.join(dist, "xmpp.js")).toString();
const sourceMap = fs
.readFileSync(path.join(dist, "xmpp.js.map"))
.toString();
const { code, map, error } = minify(bundled, {
sourceMap: {
content: sourceMap,
url: "xmpp.min.js.map",
filename: "xmpp.min.js",
},
});
if (error) return console.error(error);
fs.writeFileSync(path.join(dist, "xmpp.min.js"), code);
fs.writeFileSync(path.join(dist, "xmpp.min.js.map"), map);
});
40 changes: 0 additions & 40 deletions bundle.js

This file was deleted.

6 changes: 5 additions & 1 deletion eslint.config.mjs → eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default [
jsx: true,
},
},
sourceType: "script",
sourceType: "module",
},

rules: {
Expand Down Expand Up @@ -65,6 +65,10 @@ export default [
"error",
{ allowModules: ["ava", "sinon", "@xmpp/test"] },
],
"n/no-extraneous-import": [
"error",
{ allowModules: ["ava", "sinon", "@xmpp/test"] },
],

// promise
// https://github.com/xjamundx/eslint-plugin-promise
Expand Down
Loading

0 comments on commit bb59083

Please sign in to comment.