@modern-js/node-bundle-require 1.1.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.
@@ -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';
@@ -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))
@@ -132,7 +132,7 @@ export async function bundleRequire(filepath, options) {
132
132
  mod = await req(outfile);
133
133
  } finally {
134
134
  // Remove the outfile after executed
135
- await fs.unlink(outfile);
135
+ fs.unlinkSync(outfile);
136
136
  }
137
137
 
138
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
 
@@ -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))
@@ -148,7 +149,7 @@ async function bundleRequire(filepath, options) {
148
149
  mod = await req(outfile);
149
150
  } finally {
150
151
  // Remove the outfile after executed
151
- await _promises.default.unlink(outfile);
152
+ _fs.default.unlinkSync(outfile);
152
153
  }
153
154
 
154
155
  return mod;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/node-bundle-require",
3
- "version": "1.1.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.1.0",
35
- "@modern-js/module-tools": "^1.1.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';
@@ -113,7 +113,7 @@ export async function bundleRequire(filepath: string, options?: Options) {
113
113
  name: 'replace-path',
114
114
  setup(ctx) {
115
115
  ctx.onLoad({ filter: JS_EXT_RE }, async args => {
116
- const contents = await fs.readFile(args.path, 'utf-8');
116
+ const contents = fs.readFileSync(args.path, 'utf-8');
117
117
  return {
118
118
  contents: contents
119
119
  .replace(/\b__filename\b/g, JSON.stringify(args.path))
@@ -156,7 +156,7 @@ export async function bundleRequire(filepath: string, options?: Options) {
156
156
  mod = await req(outfile);
157
157
  } finally {
158
158
  // Remove the outfile after executed
159
- await fs.unlink(outfile);
159
+ fs.unlinkSync(outfile);
160
160
  }
161
161
 
162
162
  return mod;