@modern-js/node-bundle-require 1.0.0 → 1.1.1

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,23 @@
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
+
15
+ ## 1.0.1
16
+
17
+ ### Patch Changes
18
+
19
+ - fix(require): external regexp
20
+
3
21
  ## 1.0.0
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -17,10 +17,7 @@
17
17
 
18
18
  > 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.
19
19
 
20
- - 介绍 Modern.js (即将上线)
21
- - [迈入现代 Web 开发](https://zhuanlan.zhihu.com/p/386607009)
22
- - [现代 Web 开发者问卷调查报告](https://zhuanlan.zhihu.com/p/403206195)
23
- - [字节跳动是如何落地微前端的](https://mp.weixin.qq.com/s/L9wbfNG5fTXF5bx7dcgj4Q)
20
+ - [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)
24
21
 
25
22
  ## Getting Started
26
23
 
@@ -8,7 +8,11 @@ import fs from 'fs/promises';
8
8
  import path from 'path';
9
9
  import { randomUUID } from 'crypto';
10
10
  import { build } from 'esbuild';
11
- const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/;
11
+ const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/; // Must not start with "/" or "./" or "../"
12
+ // "/test/node_modules/foo"
13
+ // "c:/node_modules/foo"
14
+
15
+ export const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
12
16
  const CACHE_DIR = path.relative(process.cwd(), './node_modules/.node-bundle-require');
13
17
 
14
18
  function inferLoader(ext) {
@@ -102,15 +106,21 @@ export async function bundleRequire(filepath, options) {
102
106
  {
103
107
  name: 'make-all-packages-external',
104
108
 
105
- setup(build) {
106
- const filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/; // Must not start with "/" or "./" or "../"
109
+ setup(_build) {
110
+ _build.onResolve({
111
+ filter: EXTERNAL_REGEXP
112
+ }, args => {
113
+ let external = true; // FIXME: windows external entrypoint
107
114
 
108
- build.onResolve({
109
- filter
110
- }, args => ({
111
- path: args.path,
112
- external: true
113
- }));
115
+ if (args.kind === 'entry-point') {
116
+ external = false;
117
+ }
118
+
119
+ return {
120
+ path: args.path,
121
+ external
122
+ };
123
+ });
114
124
  }
115
125
 
116
126
  }]
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.EXTERNAL_REGEXP = void 0;
6
7
  exports.bundleRequire = bundleRequire;
7
8
 
8
9
  var _promises = _interopRequireDefault(require("fs/promises"));
@@ -21,7 +22,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
21
22
 
22
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; }
23
24
 
24
- const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/;
25
+ const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/; // Must not start with "/" or "./" or "../"
26
+ // "/test/node_modules/foo"
27
+ // "c:/node_modules/foo"
28
+
29
+ const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
30
+ exports.EXTERNAL_REGEXP = EXTERNAL_REGEXP;
25
31
 
26
32
  const CACHE_DIR = _path.default.relative(process.cwd(), './node_modules/.node-bundle-require');
27
33
 
@@ -116,15 +122,21 @@ async function bundleRequire(filepath, options) {
116
122
  {
117
123
  name: 'make-all-packages-external',
118
124
 
119
- setup(build) {
120
- const filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/; // Must not start with "/" or "./" or "../"
125
+ setup(_build) {
126
+ _build.onResolve({
127
+ filter: EXTERNAL_REGEXP
128
+ }, args => {
129
+ let external = true; // FIXME: windows external entrypoint
121
130
 
122
- build.onResolve({
123
- filter
124
- }, args => ({
125
- path: args.path,
126
- external: true
127
- }));
131
+ if (args.kind === 'entry-point') {
132
+ external = false;
133
+ }
134
+
135
+ return {
136
+ path: args.path,
137
+ external
138
+ };
139
+ });
128
140
  }
129
141
 
130
142
  }]
@@ -1,4 +1,5 @@
1
1
  import { Plugin, BuildOptions } from 'esbuild';
2
+ export declare const EXTERNAL_REGEXP: RegExp;
2
3
  export interface Options {
3
4
  /**
4
5
  * The `require` function that is used to load the output file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/node-bundle-require",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
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",
@@ -31,8 +31,8 @@
31
31
  "esbuild": "^0.13.8"
32
32
  },
33
33
  "devDependencies": {
34
- "@modern-js/plugin-testing": "^1.0.0",
35
- "@modern-js/module-tools": "^1.0.0",
34
+ "@modern-js/plugin-testing": "^1.1.0",
35
+ "@modern-js/module-tools": "^1.1.0",
36
36
  "@types/jest": "^26.0.9",
37
37
  "@types/node": "^14",
38
38
  "typescript": "^4"
package/src/index.ts CHANGED
@@ -5,6 +5,11 @@ import { build, Loader, Plugin, BuildOptions } from 'esbuild';
5
5
 
6
6
  const JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/;
7
7
 
8
+ // Must not start with "/" or "./" or "../"
9
+ // "/test/node_modules/foo"
10
+ // "c:/node_modules/foo"
11
+ export const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
12
+
8
13
  const CACHE_DIR = path.relative(
9
14
  process.cwd(),
10
15
  './node_modules/.node-bundle-require',
@@ -128,12 +133,18 @@ export async function bundleRequire(filepath: string, options?: Options) {
128
133
  // https://github.com/evanw/esbuild/issues/619#issuecomment-751995294
129
134
  {
130
135
  name: 'make-all-packages-external',
131
- setup(build) {
132
- const filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/; // Must not start with "/" or "./" or "../"
133
- build.onResolve({ filter }, args => ({
134
- path: args.path,
135
- external: true,
136
- }));
136
+ setup(_build) {
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
+ });
137
148
  },
138
149
  },
139
150
  ],
@@ -1,6 +1,6 @@
1
1
  module.exports = {
2
- extends: "@modern-js-app",
2
+ extends: '@modern-js',
3
3
  parserOptions: {
4
- project: require.resolve('tsconfig.json')
5
- }
6
- }
4
+ project: require.resolve('./tsconfig.json'),
5
+ },
6
+ };
@@ -1 +1 @@
1
- export const filename: string = __filename
1
+ export const filename: string = __filename;
@@ -1,5 +1,5 @@
1
- import * as a from './a'
1
+ import * as a from './a';
2
2
 
3
3
  export default {
4
4
  a,
5
- }
5
+ };
@@ -1,7 +1,19 @@
1
- import path from 'path'
2
- import { bundleRequire } from '..'
1
+ import path from 'path';
2
+ import { bundleRequire, EXTERNAL_REGEXP } from '../src';
3
3
 
4
- test('main', async () => {
5
- const result = await bundleRequire(path.join(__dirname, './fixture/input.ts'))
6
- expect(result.default.a.filename.endsWith('a.ts')).toEqual(true)
7
- })
4
+ test('require', async () => {
5
+ const result = await bundleRequire(
6
+ path.join(__dirname, './fixture/input.ts'),
7
+ );
8
+ expect(result.default.a.filename.endsWith('a.ts')).toEqual(true);
9
+ });
10
+
11
+ describe('external regexp', () => {
12
+ expect(EXTERNAL_REGEXP.test('./test')).toBeFalsy();
13
+ expect(EXTERNAL_REGEXP.test('/test')).toBeFalsy();
14
+ expect(EXTERNAL_REGEXP.test('c:/foo')).toBeTruthy();
15
+ expect(EXTERNAL_REGEXP.test('C:/foo')).toBeTruthy();
16
+ expect(EXTERNAL_REGEXP.test('c:/node_modules/foo')).toBeTruthy();
17
+ expect(EXTERNAL_REGEXP.test('foo')).toBeTruthy();
18
+ expect(EXTERNAL_REGEXP.test('/test/node_modules')).toBeFalsy();
19
+ });
@@ -1,2 +1,2 @@
1
- ///<reference types="@modern-js/module-tools/types" />
2
- ///<reference types="@modern-js/plugin-testing/type" />
1
+ /// <reference types="@modern-js/module-tools/types" />
2
+ /// <reference types="@modern-js/plugin-testing/type" />