@modern-js/node-bundle-require 1.0.1 → 1.1.2-canary.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,5 +1,17 @@
1
1
  # @modern-js/1.0.0-rc.19
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 0fa83663: support more .env files
8
+
9
+ ## 1.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 96119db2: Relese v1.1.0
14
+
3
15
  ## 1.0.1
4
16
 
5
17
  ### Patch Changes
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
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';
7
+ import fs from 'fs';
8
8
  import path from 'path';
9
9
  import { randomUUID } from 'crypto';
10
10
  import { build } from 'esbuild';
@@ -12,7 +12,7 @@ const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/; // Must not start with "/" or ".
12
12
  // "/test/node_modules/foo"
13
13
  // "c:/node_modules/foo"
14
14
 
15
- export const EXTERNAL_REGEXP = /^([[a-zA-Z\]:].*node_modules)|^[a-zA-Z]{2,}:|^[a-zA-Z]{3,}|^(\/[a-zA-Z].*node_modules.*)/;
15
+ export const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
16
16
  const CACHE_DIR = path.relative(process.cwd(), './node_modules/.node-bundle-require');
17
17
 
18
18
  function inferLoader(ext) {
@@ -94,7 +94,7 @@ export async function bundleRequire(filepath, options) {
94
94
  ctx.onLoad({
95
95
  filter: JS_EXT_RE
96
96
  }, async args => {
97
- const contents = await fs.readFile(args.path, 'utf-8');
97
+ const contents = fs.readFileSync(args.path, 'utf-8');
98
98
  return {
99
99
  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
100
  loader: inferLoader(path.extname(args.path))
@@ -109,10 +109,18 @@ export async function bundleRequire(filepath, options) {
109
109
  setup(_build) {
110
110
  _build.onResolve({
111
111
  filter: EXTERNAL_REGEXP
112
- }, args => ({
113
- path: args.path,
114
- external: true
115
- }));
112
+ }, args => {
113
+ let external = true; // FIXME: windows external entrypoint
114
+
115
+ if (args.kind === 'entry-point') {
116
+ external = false;
117
+ }
118
+
119
+ return {
120
+ path: args.path,
121
+ external
122
+ };
123
+ });
116
124
  }
117
125
 
118
126
  }]
@@ -124,7 +132,7 @@ export async function bundleRequire(filepath, options) {
124
132
  mod = await req(outfile);
125
133
  } finally {
126
134
  // Remove the outfile after executed
127
- await fs.unlink(outfile);
135
+ fs.unlinkSync(outfile);
128
136
  }
129
137
 
130
138
  return mod;
@@ -6,7 +6,7 @@ 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"));
9
+ var _fs = _interopRequireDefault(require("fs"));
10
10
 
11
11
  var _path = _interopRequireDefault(require("path"));
12
12
 
@@ -26,7 +26,7 @@ const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/; // Must not start with "/" or ".
26
26
  // "/test/node_modules/foo"
27
27
  // "c:/node_modules/foo"
28
28
 
29
- const EXTERNAL_REGEXP = /^([[a-zA-Z\]:].*node_modules)|^[a-zA-Z]{2,}:|^[a-zA-Z]{3,}|^(\/[a-zA-Z].*node_modules.*)/;
29
+ const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
30
30
  exports.EXTERNAL_REGEXP = EXTERNAL_REGEXP;
31
31
 
32
32
  const CACHE_DIR = _path.default.relative(process.cwd(), './node_modules/.node-bundle-require');
@@ -110,7 +110,8 @@ async function bundleRequire(filepath, options) {
110
110
  ctx.onLoad({
111
111
  filter: JS_EXT_RE
112
112
  }, async args => {
113
- const contents = await _promises.default.readFile(args.path, 'utf-8');
113
+ const contents = _fs.default.readFileSync(args.path, 'utf-8');
114
+
114
115
  return {
115
116
  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
117
  loader: inferLoader(_path.default.extname(args.path))
@@ -125,10 +126,18 @@ async function bundleRequire(filepath, options) {
125
126
  setup(_build) {
126
127
  _build.onResolve({
127
128
  filter: EXTERNAL_REGEXP
128
- }, args => ({
129
- path: args.path,
130
- external: true
131
- }));
129
+ }, args => {
130
+ let external = true; // FIXME: windows external entrypoint
131
+
132
+ if (args.kind === 'entry-point') {
133
+ external = false;
134
+ }
135
+
136
+ return {
137
+ path: args.path,
138
+ external
139
+ };
140
+ });
132
141
  }
133
142
 
134
143
  }]
@@ -140,7 +149,7 @@ async function bundleRequire(filepath, options) {
140
149
  mod = await req(outfile);
141
150
  } finally {
142
151
  // Remove the outfile after executed
143
- await _promises.default.unlink(outfile);
152
+ _fs.default.unlinkSync(outfile);
144
153
  }
145
154
 
146
155
  return mod;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/node-bundle-require",
3
- "version": "1.0.1",
3
+ "version": "1.1.2-canary.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",
@@ -26,13 +26,19 @@
26
26
  "default": "./dist/js/treeshaking/index.js"
27
27
  }
28
28
  },
29
+ "scripts": {
30
+ "prepare": "pnpm build",
31
+ "new": "modern new",
32
+ "build": "modern build",
33
+ "test": "modern test --passWithNoTests"
34
+ },
29
35
  "dependencies": {
30
36
  "@babel/runtime": "^7",
31
37
  "esbuild": "^0.13.8"
32
38
  },
33
39
  "devDependencies": {
34
- "@modern-js/plugin-testing": "^1.0.0",
35
- "@modern-js/module-tools": "^1.0.0",
40
+ "@modern-js/plugin-testing": "^1.1.1",
41
+ "@modern-js/module-tools": "^1.1.1",
36
42
  "@types/jest": "^26.0.9",
37
43
  "@types/node": "^14",
38
44
  "typescript": "^4"
@@ -46,10 +52,5 @@
46
52
  "publishConfig": {
47
53
  "registry": "https://registry.npmjs.org/",
48
54
  "access": "public"
49
- },
50
- "scripts": {
51
- "new": "modern new",
52
- "build": "modern build",
53
- "test": "modern test --passWithNoTests"
54
55
  }
55
- }
56
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import fs from 'fs/promises';
1
+ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { randomUUID } from 'crypto';
4
4
  import { build, Loader, Plugin, BuildOptions } from 'esbuild';
@@ -8,8 +8,7 @@ const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/;
8
8
  // Must not start with "/" or "./" or "../"
9
9
  // "/test/node_modules/foo"
10
10
  // "c:/node_modules/foo"
11
- export const EXTERNAL_REGEXP =
12
- /^([[a-zA-Z\]:].*node_modules)|^[a-zA-Z]{2,}:|^[a-zA-Z]{3,}|^(\/[a-zA-Z].*node_modules.*)/;
11
+ export const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
13
12
 
14
13
  const CACHE_DIR = path.relative(
15
14
  process.cwd(),
@@ -114,7 +113,7 @@ export async function bundleRequire(filepath: string, options?: Options) {
114
113
  name: 'replace-path',
115
114
  setup(ctx) {
116
115
  ctx.onLoad({ filter: JS_EXT_RE }, async args => {
117
- const contents = await fs.readFile(args.path, 'utf-8');
116
+ const contents = fs.readFileSync(args.path, 'utf-8');
118
117
  return {
119
118
  contents: contents
120
119
  .replace(/\b__filename\b/g, JSON.stringify(args.path))
@@ -135,10 +134,17 @@ export async function bundleRequire(filepath: string, options?: Options) {
135
134
  {
136
135
  name: 'make-all-packages-external',
137
136
  setup(_build) {
138
- _build.onResolve({ filter: EXTERNAL_REGEXP }, args => ({
139
- path: args.path,
140
- external: true,
141
- }));
137
+ _build.onResolve({ filter: EXTERNAL_REGEXP }, args => {
138
+ let external = true;
139
+ // FIXME: windows external entrypoint
140
+ if (args.kind === 'entry-point') {
141
+ external = false;
142
+ }
143
+ return {
144
+ path: args.path,
145
+ external,
146
+ };
147
+ });
142
148
  },
143
149
  },
144
150
  ],
@@ -150,7 +156,7 @@ export async function bundleRequire(filepath: string, options?: Options) {
150
156
  mod = await req(outfile);
151
157
  } finally {
152
158
  // Remove the outfile after executed
153
- await fs.unlink(outfile);
159
+ fs.unlinkSync(outfile);
154
160
  }
155
161
 
156
162
  return mod;
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { bundleRequire, EXTERNAL_REGEXP } from '..';
2
+ import { bundleRequire, EXTERNAL_REGEXP } from '../src';
3
3
 
4
4
  test('require', async () => {
5
5
  const result = await bundleRequire(
@@ -11,9 +11,9 @@ test('require', async () => {
11
11
  describe('external regexp', () => {
12
12
  expect(EXTERNAL_REGEXP.test('./test')).toBeFalsy();
13
13
  expect(EXTERNAL_REGEXP.test('/test')).toBeFalsy();
14
- expect(EXTERNAL_REGEXP.test('c:/foo')).toBeFalsy();
15
- expect(EXTERNAL_REGEXP.test('C:/foo')).toBeFalsy();
14
+ expect(EXTERNAL_REGEXP.test('c:/foo')).toBeTruthy();
15
+ expect(EXTERNAL_REGEXP.test('C:/foo')).toBeTruthy();
16
16
  expect(EXTERNAL_REGEXP.test('c:/node_modules/foo')).toBeTruthy();
17
17
  expect(EXTERNAL_REGEXP.test('foo')).toBeTruthy();
18
- expect(EXTERNAL_REGEXP.test('/test/node_modules')).toBeTruthy();
18
+ expect(EXTERNAL_REGEXP.test('/test/node_modules')).toBeFalsy();
19
19
  });