@modern-js/node-bundle-require 1.0.2 → 1.2.0

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/CHANGELOG.md CHANGED
@@ -1,10 +1,26 @@
1
1
  # @modern-js/1.0.0-rc.19
2
2
 
3
- ## 1.0.2
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cfe11628: Make Modern.js self bootstraping
4
8
 
5
9
  ### Patch Changes
6
10
 
7
- - release 1.0.1
11
+ - 59cbcb77: fix esbuild error when project's tsconfig.json sets "target:es5"
12
+
13
+ ## 1.1.1
14
+
15
+ ### Patch Changes
16
+
17
+ - 0fa83663: support more .env files
18
+
19
+ ## 1.1.0
20
+
21
+ ### Minor Changes
22
+
23
+ - 96119db2: Relese v1.1.0
8
24
 
9
25
  ## 1.0.1
10
26
 
@@ -1,12 +1,12 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
2
 
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import fs from 'fs/promises';
8
7
  import path from 'path';
9
8
  import { randomUUID } from 'crypto';
9
+ import { fs } from '@modern-js/utils';
10
10
  import { build } from 'esbuild';
11
11
  const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/; // Must not start with "/" or "./" or "../"
12
12
  // "/test/node_modules/foo"
@@ -39,7 +39,11 @@ export async function bundleRequire(filepath, options) {
39
39
  outfile,
40
40
  format: 'cjs',
41
41
  platform: 'node',
42
- bundle: true
42
+ bundle: true,
43
+ // fix transforming error when the project's tsconfig.json
44
+ // sets `target: "es5"`
45
+ // reference: https://github.com/evanw/esbuild/releases/tag/v0.12.6
46
+ target: 'esnext'
43
47
  }, options === null || options === void 0 ? void 0 : options.esbuildOptions), {}, {
44
48
  plugins: [...((options === null || options === void 0 ? void 0 : options.esbuildPlugins) || []), // https://github.com/evanw/esbuild/issues/1051#issuecomment-806325487
45
49
  {
@@ -94,7 +98,7 @@ export async function bundleRequire(filepath, options) {
94
98
  ctx.onLoad({
95
99
  filter: JS_EXT_RE
96
100
  }, async args => {
97
- const contents = await fs.readFile(args.path, 'utf-8');
101
+ const contents = fs.readFileSync(args.path, 'utf-8');
98
102
  return {
99
103
  contents: contents.replace(/\b__filename\b/g, JSON.stringify(args.path)).replace(/\b__dirname\b/g, JSON.stringify(path.dirname(args.path))).replace(/\bimport\.meta\.url\b/g, JSON.stringify(`file://${args.path}`)),
100
104
  loader: inferLoader(path.extname(args.path))
@@ -132,7 +136,7 @@ export async function bundleRequire(filepath, options) {
132
136
  mod = await req(outfile);
133
137
  } finally {
134
138
  // Remove the outfile after executed
135
- await fs.unlink(outfile);
139
+ fs.unlinkSync(outfile);
136
140
  }
137
141
 
138
142
  return mod;
@@ -6,19 +6,19 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.EXTERNAL_REGEXP = void 0;
7
7
  exports.bundleRequire = bundleRequire;
8
8
 
9
- var _promises = _interopRequireDefault(require("fs/promises"));
10
-
11
9
  var _path = _interopRequireDefault(require("path"));
12
10
 
13
11
  var _crypto = require("crypto");
14
12
 
13
+ var _utils = require("@modern-js/utils");
14
+
15
15
  var _esbuild = require("esbuild");
16
16
 
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
18
 
19
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
19
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
20
20
 
21
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
21
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
22
22
 
23
23
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
24
 
@@ -55,7 +55,11 @@ async function bundleRequire(filepath, options) {
55
55
  outfile,
56
56
  format: 'cjs',
57
57
  platform: 'node',
58
- bundle: true
58
+ bundle: true,
59
+ // fix transforming error when the project's tsconfig.json
60
+ // sets `target: "es5"`
61
+ // reference: https://github.com/evanw/esbuild/releases/tag/v0.12.6
62
+ target: 'esnext'
59
63
  }, options === null || options === void 0 ? void 0 : options.esbuildOptions), {}, {
60
64
  plugins: [...((options === null || options === void 0 ? void 0 : options.esbuildPlugins) || []), // https://github.com/evanw/esbuild/issues/1051#issuecomment-806325487
61
65
  {
@@ -110,7 +114,8 @@ async function bundleRequire(filepath, options) {
110
114
  ctx.onLoad({
111
115
  filter: JS_EXT_RE
112
116
  }, async args => {
113
- const contents = await _promises.default.readFile(args.path, 'utf-8');
117
+ const contents = _utils.fs.readFileSync(args.path, 'utf-8');
118
+
114
119
  return {
115
120
  contents: contents.replace(/\b__filename\b/g, JSON.stringify(args.path)).replace(/\b__dirname\b/g, JSON.stringify(_path.default.dirname(args.path))).replace(/\bimport\.meta\.url\b/g, JSON.stringify(`file://${args.path}`)),
116
121
  loader: inferLoader(_path.default.extname(args.path))
@@ -148,7 +153,7 @@ async function bundleRequire(filepath, options) {
148
153
  mod = await req(outfile);
149
154
  } finally {
150
155
  // Remove the outfile after executed
151
- await _promises.default.unlink(outfile);
156
+ _utils.fs.unlinkSync(outfile);
152
157
  }
153
158
 
154
159
  return mod;
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ const sharedConfig = require('@scripts/jest-config');
2
+
3
+ /** @type {import('@jest/types').Config.InitialOptions} */
4
+ module.exports = {
5
+ // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
+ ...sharedConfig,
7
+ rootDir: __dirname,
8
+ };
package/modern.config.js CHANGED
@@ -1,10 +1,2 @@
1
1
  /** @type {import('@modern-js/module-tools').UserConfig} */
2
- module.exports = {
3
- testing: {
4
- jest: {
5
- collectCoverage: true,
6
- collectCoverageFrom: ['src/**/*.ts'],
7
- coveragePathIgnorePatterns: ['/node_modules/'],
8
- },
9
- },
10
- };
2
+ module.exports = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/node-bundle-require",
3
- "version": "1.0.2",
3
+ "version": "1.2.0",
4
4
  "description": "The meta-framework suite designed from scratch for frontend-focused modern web development.",
5
5
  "homepage": "https://modernjs.dev",
6
6
  "bugs": "https://github.com/modern-js-dev/modern.js/issues",
@@ -20,6 +20,7 @@
20
20
  "exports": {
21
21
  ".": {
22
22
  "node": {
23
+ "jsnext:source": "./src/index.ts",
23
24
  "import": "./dist/js/modern/index.js",
24
25
  "require": "./dist/js/node/index.js"
25
26
  },
@@ -31,11 +32,13 @@
31
32
  "esbuild": "^0.13.8"
32
33
  },
33
34
  "devDependencies": {
34
- "@modern-js/plugin-testing": "^1.0.2",
35
- "@modern-js/module-tools": "^1.0.2",
35
+ "@scripts/build": "0.0.0",
36
+ "@modern-js/utils": "^1.2.0",
36
37
  "@types/jest": "^26.0.9",
37
38
  "@types/node": "^14",
38
- "typescript": "^4"
39
+ "typescript": "^4",
40
+ "jest": "^27",
41
+ "@scripts/jest-config": "0.0.0"
39
42
  },
40
43
  "sideEffects": false,
41
44
  "modernConfig": {
@@ -45,11 +48,13 @@
45
48
  },
46
49
  "publishConfig": {
47
50
  "registry": "https://registry.npmjs.org/",
48
- "access": "public"
51
+ "access": "public",
52
+ "types": "./dist/types/index.d.ts"
49
53
  },
50
54
  "scripts": {
51
55
  "new": "modern new",
52
56
  "build": "modern build",
53
- "test": "modern test --passWithNoTests"
54
- }
57
+ "test": "jest --passWithNoTests"
58
+ },
59
+ "readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
55
60
  }
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- import fs from 'fs/promises';
2
1
  import path from 'path';
3
2
  import { randomUUID } from 'crypto';
3
+ import { fs } from '@modern-js/utils';
4
4
  import { build, Loader, Plugin, BuildOptions } from 'esbuild';
5
5
 
6
6
  const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/;
@@ -66,6 +66,10 @@ export async function bundleRequire(filepath: string, options?: Options) {
66
66
  format: 'cjs',
67
67
  platform: 'node',
68
68
  bundle: true,
69
+ // fix transforming error when the project's tsconfig.json
70
+ // sets `target: "es5"`
71
+ // reference: https://github.com/evanw/esbuild/releases/tag/v0.12.6
72
+ target: 'esnext',
69
73
  ...options?.esbuildOptions,
70
74
  plugins: [
71
75
  ...(options?.esbuildPlugins || []),
@@ -113,7 +117,7 @@ export async function bundleRequire(filepath: string, options?: Options) {
113
117
  name: 'replace-path',
114
118
  setup(ctx) {
115
119
  ctx.onLoad({ filter: JS_EXT_RE }, async args => {
116
- const contents = await fs.readFile(args.path, 'utf-8');
120
+ const contents = fs.readFileSync(args.path, 'utf-8');
117
121
  return {
118
122
  contents: contents
119
123
  .replace(/\b__filename\b/g, JSON.stringify(args.path))
@@ -156,7 +160,7 @@ export async function bundleRequire(filepath: string, options?: Options) {
156
160
  mod = await req(outfile);
157
161
  } finally {
158
162
  // Remove the outfile after executed
159
- await fs.unlink(outfile);
163
+ fs.unlinkSync(outfile);
160
164
  }
161
165
 
162
166
  return mod;
@@ -1 +1,2 @@
1
1
  export const filename: string = __filename;
2
+ export const showFileName = () => filename;
@@ -5,7 +5,14 @@ test('require', async () => {
5
5
  const result = await bundleRequire(
6
6
  path.join(__dirname, './fixture/input.ts'),
7
7
  );
8
+ // when tsconfig.json sets `compilerOptions.target` to `es5`
9
+ // normally it will met error
10
+ // So we need to manually set esbuild's target to esnext to avoid that
11
+ // These two cases above use ES6+ ability, to test whether esbuild successfuly
12
+ // works on non-ES5 files
13
+ // reference: https://github.com/evanw/esbuild/releases/tag/v0.12.6
8
14
  expect(result.default.a.filename.endsWith('a.ts')).toEqual(true);
15
+ expect(result.default.a.showFileName().endsWith('a.ts')).toEqual(true);
9
16
  });
10
17
 
11
18
  describe('external regexp', () => {
@@ -2,10 +2,9 @@
2
2
  "extends": "@modern-js/tsconfig/base",
3
3
  "compilerOptions": {
4
4
  "declaration": false,
5
+ "target": "es5",
5
6
  "jsx": "preserve",
6
7
  "baseUrl": "./",
7
- "paths": {
8
- "@/*": ["../src/*"]
9
- }
8
+ "paths": {}
10
9
  }
11
10
  }
package/tsconfig.json CHANGED
@@ -5,9 +5,7 @@
5
5
  "jsx": "preserve",
6
6
  "baseUrl": "./",
7
7
  "isolatedModules": true,
8
- "paths": {
9
- "@/*": ["./src/*"]
10
- }
8
+ "paths": {}
11
9
  },
12
10
  "include": ["src"]
13
11
  }