@live-codes/browser-compilers 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-codes/browser-compilers",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Compilers that run in the browser, for use in livecodes.io",
5
5
  "author": "Hatem Hosny",
6
6
  "license": "MIT",
@@ -30,6 +30,9 @@
30
30
  "@esbuild-plugins/node-modules-polyfill": "0.1.4",
31
31
  "@mdx-js/mdx": "2.0.0",
32
32
  "@prettier/plugin-pug": "1.19.2",
33
+ "@testing-library/dom": "8.12.0",
34
+ "@testing-library/jest-dom": "5.16.3",
35
+ "@testing-library/react": "12.1.4",
33
36
  "@webassemblyjs/wast-refmt": "1.11.1",
34
37
  "babel-preset-solid": "1.3.5",
35
38
  "esbuild-plugin-cache": "0.2.9",
@@ -0,0 +1,45 @@
1
+ var fs = require('fs');
2
+ var path = require('path');
3
+
4
+ const patch = (
5
+ /** @type {string} */ filePath,
6
+ /** @type {Record<string, string>} */ replacements = {},
7
+ ) =>
8
+ new Promise((resolve, reject) => {
9
+ fs.readFile(path.resolve(filePath), 'utf8', function (err, data) {
10
+ if (err) return reject(err);
11
+
12
+ var result = data;
13
+ for (const key of Object.keys(replacements)) {
14
+ result = result.split(key).join(replacements[key]);
15
+ }
16
+
17
+ fs.writeFile(path.resolve(filePath), result, 'utf8', function (err) {
18
+ if (err) return reject(err);
19
+
20
+ resolve();
21
+ });
22
+ });
23
+ });
24
+
25
+ // https://github.com/evanw/esbuild/issues/566#issuecomment-735551834
26
+ const externalCjsToEsmPlugin = (external) => ({
27
+ name: 'external',
28
+ setup(build) {
29
+ let escape = (text) => `^${text.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')}$`;
30
+ let filter = new RegExp(external.map(escape).join('|'));
31
+ build.onResolve({ filter: /.*/, namespace: 'external' }, (args) => ({
32
+ path: args.path,
33
+ external: true,
34
+ }));
35
+ build.onResolve({ filter }, (args) => ({
36
+ path: args.path,
37
+ namespace: 'external',
38
+ }));
39
+ build.onLoad({ filter: /.*/, namespace: 'external' }, (args) => ({
40
+ contents: `export * from ${JSON.stringify(args.path)}`,
41
+ }));
42
+ },
43
+ });
44
+
45
+ module.exports = { patch, externalCjsToEsmPlugin };
@@ -5,7 +5,7 @@ const esbuild = require('esbuild');
5
5
  const NodeModulesPolyfills = require('@esbuild-plugins/node-modules-polyfill').default;
6
6
  const GlobalsPolyfills = require('@esbuild-plugins/node-globals-polyfill').default;
7
7
 
8
- const { patch } = require('./patch');
8
+ const { patch, externalCjsToEsmPlugin } = require('./utils');
9
9
 
10
10
  const nodePolyfills = [
11
11
  NodeModulesPolyfills(),
@@ -49,7 +49,7 @@ patch('node_modules/sass/sass.dart.js', {
49
49
  // Eslint
50
50
  esbuild.build({
51
51
  ...baseOptions,
52
- entryPoints: ['node_modules/eslint/lib/linter/linter.js'],
52
+ entryPoints: ['vendor_modules/imports/eslint.js'],
53
53
  outfile: 'dist/eslint/eslint.js',
54
54
  globalName: 'eslint',
55
55
  plugins: nodePolyfills,
@@ -258,3 +258,24 @@ fs.copyFileSync(
258
258
  path.resolve(vendor_modules_src + '/svgbob-wasm/svgbob-wasm.js'),
259
259
  path.resolve(targetDir + '/svgbob-wasm/svgbob-wasm.js'),
260
260
  );
261
+
262
+ // @testing-library
263
+ ['dom.js', 'jest-dom.js', 'react.js'].forEach(
264
+ // entryPoints did not work properly!
265
+ (mod) => {
266
+ esbuild
267
+ .build({
268
+ ...baseOptions,
269
+ entryPoints: ['vendor_modules/imports/@testing-library/' + mod],
270
+ outdir: 'dist/@testing-library/',
271
+ format: 'esm',
272
+ plugins: [externalCjsToEsmPlugin(['react'])],
273
+ })
274
+ .then(() => {
275
+ if (mod !== 'jest-dom.js') return;
276
+ patch('dist/@testing-library/jest-dom.js', {
277
+ 'expect.extend': 'window.jestLite?.core.expect.extend',
278
+ });
279
+ });
280
+ },
281
+ );
@@ -0,0 +1 @@
1
+ export * from '@testing-library/dom';
@@ -0,0 +1 @@
1
+ export * from '@testing-library/jest-dom';
@@ -0,0 +1 @@
1
+ export * from '@testing-library/react';
@@ -0,0 +1 @@
1
+ export { Linter } from '../../node_modules/eslint/lib/linter/linter.js';
package/scripts/patch.js DELETED
@@ -1,25 +0,0 @@
1
- var fs = require('fs');
2
- var path = require('path');
3
-
4
- const patch = (
5
- /** @type {string} */ filePath,
6
- /** @type {Record<string, string>} */ replacements = {},
7
- ) =>
8
- new Promise((resolve, reject) => {
9
- fs.readFile(path.resolve(filePath), 'utf8', function (err, data) {
10
- if (err) return reject(err);
11
-
12
- var result = data;
13
- for (const key of Object.keys(replacements)) {
14
- result = result.split(key).join(replacements[key]);
15
- }
16
-
17
- fs.writeFile(path.resolve(filePath), result, 'utf8', function (err) {
18
- if (err) return reject(err);
19
-
20
- resolve();
21
- });
22
- });
23
- });
24
-
25
- module.exports = { patch };