fyn 3.0.4 → 3.1.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/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "fyn",
3
- "version": "3.0.4",
3
+ "version": "3.1.0",
4
4
  "description": "fyn is the NPM for fynpo -- a zero setup monorepo tool",
5
- "main": "./bin/fyn.js",
5
+ "main": "./bin/index.mjs",
6
6
  "homepage": "https://github.com/jchip/fynjs/tree/main/packages/fyn",
7
7
  "license": "Apache-2.0",
8
8
  "scripts": {
@@ -10,12 +10,14 @@
10
10
  "test:watch": "vitest",
11
11
  "test:ui": "vitest --ui",
12
12
  "test:coverage": "vitest run --coverage",
13
+ "typecheck": "tsc --noEmit -p tsconfig.json",
14
+ "typecheck:gate": "node typecheck-gate.mjs",
15
+ "typecheck:baseline": "node typecheck-gate.mjs --update",
13
16
  "debug-test": "node --inspect-brk node_modules/.bin/vitest --extension ts,js,tsx,jsx,cjs,mjs test/spec",
14
- "compile-yarn": "babel yarn/src --out-dir yarn/lib",
15
17
  "build": "node build.mjs",
16
- "analyze": "ANALYZE_BUNDLE=1 xrun compile-yarn bundle",
18
+ "analyze": "ANALYZE_BUNDLE=1 xrun bundle",
17
19
  "coverage": "vitest run --coverage",
18
- "ci:check": "vitest run --coverage",
20
+ "ci:check": "node typecheck-gate.mjs && vitest run --coverage",
19
21
  "coveralls": "cat coverage/lcov.info | coveralls",
20
22
  "prepublishOnly": "xrun build",
21
23
  "postpack": "publish-util-postpack",
@@ -26,9 +28,9 @@
26
28
  "hello": "echo hello"
27
29
  },
28
30
  "bin": {
29
- "0-npx-please-run-this-for-fyn": "./bin/fyn.js",
30
- "fyn": "./bin/fyn.js",
31
- "fun": "./bin/fun.js"
31
+ "0-npx-please-run-this-for-fyn": "./bin/fyn.mjs",
32
+ "fyn": "./bin/fyn.mjs",
33
+ "fun": "./bin/fun.mjs"
32
34
  },
33
35
  "author": "Walmart GTP.js Team and Contributors",
34
36
  "publishConfig": {
@@ -79,6 +81,6 @@
79
81
  "Divya Karippath"
80
82
  ],
81
83
  "engines": {
82
- "node": ">=22.12.0"
84
+ "node": ">=22.18.0"
83
85
  }
84
86
  }
package/bin/bundle.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- var maj = parseInt(process.versions.node.split(".")[0], 10);
4
-
5
- if (maj >= 8) {
6
- try {
7
- require("../dist/v8-compile-cache");
8
- } catch (err) {
9
- if (
10
- // is error caused by module not found?
11
- (err.code &&
12
- err.code !== "MODULE_NOT_FOUND" &&
13
- err.message.indexOf("Cannot find module") < 0) ||
14
- // is the not found module the one we are trying to require?
15
- err.message.indexOf("v8-compile-cache") < 0
16
- ) {
17
- console.log(`Failed loading v8-compile-cache`, err);
18
- }
19
- }
20
- module.exports = "../dist/fyn.mjs";
21
- } else {
22
- console.log("Sorry, fyn does not support node version below 8. Your version is", maj);
23
- process.exit(1);
24
- }
package/bin/fun.js DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- "use strict";
4
-
5
- require("./index")
6
- .fun()
7
- .then(() => {
8
- process.exit(0);
9
- })
10
- .catch(err => {
11
- console.error(err);
12
- process.exit(1);
13
- });
package/bin/fyn.js DELETED
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require("./index")
4
- .run()
5
- .then(() => {
6
- process.exit(0);
7
- })
8
- .catch(err => {
9
- console.log(err);
10
- process.exit(1);
11
- });
package/bin/index.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- //
4
- // The release bundle is ESM (dist/fyn.mjs) because chalker uses top-level await to optionally
5
- // load ESM-only chalk, and no CJS output format can represent module-scope await.
6
- //
7
- // This file stays CJS so package.json can remain type: commonjs. Reaching an ESM bundle from
8
- // CJS costs one async hop, so run/fun return promises - which is what bin/fyn.js and
9
- // bin/fun.js already expected.
10
- //
11
- const Path = require("path");
12
- const { pathToFileURL } = require("url");
13
-
14
- const bundle = require("./bundle");
15
-
16
- // resolve to an absolute file URL so the import does not depend on the caller's cwd
17
- const bundleUrl = pathToFileURL(Path.join(__dirname, bundle)).href;
18
-
19
- const loadBundle = () => import(bundleUrl).then(m => m.default || m);
20
-
21
- module.exports = {
22
- run: (...args) => loadBundle().then(m => m.run(...args)),
23
- fun: (...args) => loadBundle().then(m => m.fun(...args))
24
- };
@@ -1,373 +0,0 @@
1
- 'use strict';
2
-
3
- const Module = require('module');
4
- const crypto = require('crypto');
5
- const fs = require('fs');
6
- const path = require('path');
7
- const vm = require('vm');
8
- const os = require('os');
9
-
10
- const hasOwnProperty = Object.prototype.hasOwnProperty;
11
-
12
- //------------------------------------------------------------------------------
13
- // FileSystemBlobStore
14
- //------------------------------------------------------------------------------
15
-
16
- class FileSystemBlobStore {
17
- constructor(directory, prefix) {
18
- const name = prefix ? slashEscape(prefix + '.') : '';
19
- this._blobFilename = path.join(directory, name + 'BLOB');
20
- this._mapFilename = path.join(directory, name + 'MAP');
21
- this._lockFilename = path.join(directory, name + 'LOCK');
22
- this._directory = directory;
23
- this._load();
24
- }
25
-
26
- has(key, invalidationKey) {
27
- if (hasOwnProperty.call(this._memoryBlobs, key)) {
28
- return this._invalidationKeys[key] === invalidationKey;
29
- } else if (hasOwnProperty.call(this._storedMap, key)) {
30
- return this._storedMap[key][0] === invalidationKey;
31
- }
32
- return false;
33
- }
34
-
35
- get(key, invalidationKey) {
36
- if (hasOwnProperty.call(this._memoryBlobs, key)) {
37
- if (this._invalidationKeys[key] === invalidationKey) {
38
- return this._memoryBlobs[key];
39
- }
40
- } else if (hasOwnProperty.call(this._storedMap, key)) {
41
- const mapping = this._storedMap[key];
42
- if (mapping[0] === invalidationKey) {
43
- return this._storedBlob.slice(mapping[1], mapping[2]);
44
- }
45
- }
46
- }
47
-
48
- set(key, invalidationKey, buffer) {
49
- this._invalidationKeys[key] = invalidationKey;
50
- this._memoryBlobs[key] = buffer;
51
- this._dirty = true;
52
- }
53
-
54
- delete(key) {
55
- if (hasOwnProperty.call(this._memoryBlobs, key)) {
56
- this._dirty = true;
57
- delete this._memoryBlobs[key];
58
- }
59
- if (hasOwnProperty.call(this._invalidationKeys, key)) {
60
- this._dirty = true;
61
- delete this._invalidationKeys[key];
62
- }
63
- if (hasOwnProperty.call(this._storedMap, key)) {
64
- this._dirty = true;
65
- delete this._storedMap[key];
66
- }
67
- }
68
-
69
- isDirty() {
70
- return this._dirty;
71
- }
72
-
73
- save() {
74
- const dump = this._getDump();
75
- const blobToStore = Buffer.concat(dump[0]);
76
- const mapToStore = JSON.stringify(dump[1]);
77
-
78
- try {
79
- mkdirpSync(this._directory);
80
- fs.writeFileSync(this._lockFilename, 'LOCK', {flag: 'wx'});
81
- } catch (error) {
82
- // Swallow the exception if we fail to acquire the lock.
83
- return false;
84
- }
85
-
86
- try {
87
- fs.writeFileSync(this._blobFilename, blobToStore);
88
- fs.writeFileSync(this._mapFilename, mapToStore);
89
- } finally {
90
- fs.unlinkSync(this._lockFilename);
91
- }
92
-
93
- return true;
94
- }
95
-
96
- _load() {
97
- try {
98
- this._storedBlob = fs.readFileSync(this._blobFilename);
99
- this._storedMap = JSON.parse(fs.readFileSync(this._mapFilename));
100
- } catch (e) {
101
- this._storedBlob = Buffer.alloc(0);
102
- this._storedMap = {};
103
- }
104
- this._dirty = false;
105
- this._memoryBlobs = {};
106
- this._invalidationKeys = {};
107
- }
108
-
109
- _getDump() {
110
- const buffers = [];
111
- const newMap = {};
112
- let offset = 0;
113
-
114
- function push(key, invalidationKey, buffer) {
115
- buffers.push(buffer);
116
- newMap[key] = [invalidationKey, offset, offset + buffer.length];
117
- offset += buffer.length;
118
- }
119
-
120
- for (const key of Object.keys(this._memoryBlobs)) {
121
- const buffer = this._memoryBlobs[key];
122
- const invalidationKey = this._invalidationKeys[key];
123
- push(key, invalidationKey, buffer);
124
- }
125
-
126
- for (const key of Object.keys(this._storedMap)) {
127
- if (hasOwnProperty.call(newMap, key)) continue;
128
- const mapping = this._storedMap[key];
129
- const buffer = this._storedBlob.slice(mapping[1], mapping[2]);
130
- push(key, mapping[0], buffer);
131
- }
132
-
133
- return [buffers, newMap];
134
- }
135
- }
136
-
137
- //------------------------------------------------------------------------------
138
- // NativeCompileCache
139
- //------------------------------------------------------------------------------
140
-
141
- class NativeCompileCache {
142
- constructor() {
143
- this._cacheStore = null;
144
- this._previousModuleCompile = null;
145
- }
146
-
147
- setCacheStore(cacheStore) {
148
- this._cacheStore = cacheStore;
149
- }
150
-
151
- install() {
152
- const self = this;
153
- const hasRequireResolvePaths = typeof require.resolve.paths === 'function';
154
- this._previousModuleCompile = Module.prototype._compile;
155
- Module.prototype._compile = function(content, filename) {
156
- const mod = this;
157
-
158
- function require(id) {
159
- return mod.require(id);
160
- }
161
-
162
- // https://github.com/nodejs/node/blob/v10.15.3/lib/internal/modules/cjs/helpers.js#L28
163
- function resolve(request, options) {
164
- return Module._resolveFilename(request, mod, false, options);
165
- }
166
- require.resolve = resolve;
167
-
168
- // https://github.com/nodejs/node/blob/v10.15.3/lib/internal/modules/cjs/helpers.js#L37
169
- // resolve.resolve.paths was added in v8.9.0
170
- if (hasRequireResolvePaths) {
171
- resolve.paths = function paths(request) {
172
- return Module._resolveLookupPaths(request, mod, true);
173
- };
174
- }
175
-
176
- require.main = process.mainModule;
177
-
178
- // Enable support to add extra extension types
179
- require.extensions = Module._extensions;
180
- require.cache = Module._cache;
181
-
182
- const dirname = path.dirname(filename);
183
-
184
- const compiledWrapper = self._moduleCompile(filename, content);
185
-
186
- // We skip the debugger setup because by the time we run, node has already
187
- // done that itself.
188
-
189
- // `Buffer` is included for Electron.
190
- // See https://github.com/zertosh/v8-compile-cache/pull/10#issuecomment-518042543
191
- const args = [mod.exports, require, mod, filename, dirname, process, global, Buffer];
192
- return compiledWrapper.apply(mod.exports, args);
193
- };
194
- }
195
-
196
- uninstall() {
197
- Module.prototype._compile = this._previousModuleCompile;
198
- }
199
-
200
- _moduleCompile(filename, content) {
201
- // https://github.com/nodejs/node/blob/v7.5.0/lib/module.js#L511
202
-
203
- // Remove shebang
204
- var contLen = content.length;
205
- if (contLen >= 2) {
206
- if (content.charCodeAt(0) === 35/*#*/ &&
207
- content.charCodeAt(1) === 33/*!*/) {
208
- if (contLen === 2) {
209
- // Exact match
210
- content = '';
211
- } else {
212
- // Find end of shebang line and slice it off
213
- var i = 2;
214
- for (; i < contLen; ++i) {
215
- var code = content.charCodeAt(i);
216
- if (code === 10/*\n*/ || code === 13/*\r*/) break;
217
- }
218
- if (i === contLen) {
219
- content = '';
220
- } else {
221
- // Note that this actually includes the newline character(s) in the
222
- // new output. This duplicates the behavior of the regular
223
- // expression that was previously used to replace the shebang line
224
- content = content.slice(i);
225
- }
226
- }
227
- }
228
- }
229
-
230
- // create wrapper function
231
- var wrapper = Module.wrap(content);
232
-
233
- var invalidationKey = crypto
234
- .createHash('sha1')
235
- .update(content, 'utf8')
236
- .digest('hex');
237
-
238
- var buffer = this._cacheStore.get(filename, invalidationKey);
239
-
240
- var script = new vm.Script(wrapper, {
241
- filename: filename,
242
- lineOffset: 0,
243
- displayErrors: true,
244
- cachedData: buffer,
245
- produceCachedData: true,
246
- });
247
-
248
- if (script.cachedDataProduced) {
249
- this._cacheStore.set(filename, invalidationKey, script.cachedData);
250
- } else if (script.cachedDataRejected) {
251
- this._cacheStore.delete(filename);
252
- }
253
-
254
- var compiledWrapper = script.runInThisContext({
255
- filename: filename,
256
- lineOffset: 0,
257
- columnOffset: 0,
258
- displayErrors: true,
259
- });
260
-
261
- return compiledWrapper;
262
- }
263
- }
264
-
265
- //------------------------------------------------------------------------------
266
- // utilities
267
- //
268
- // https://github.com/substack/node-mkdirp/blob/f2003bb/index.js#L55-L98
269
- // https://github.com/zertosh/slash-escape/blob/e7ebb99/slash-escape.js
270
- //------------------------------------------------------------------------------
271
-
272
- function mkdirpSync(p_) {
273
- _mkdirpSync(path.resolve(p_), 0o777);
274
- }
275
-
276
- function _mkdirpSync(p, mode) {
277
- try {
278
- fs.mkdirSync(p, mode);
279
- } catch (err0) {
280
- if (err0.code === 'ENOENT') {
281
- _mkdirpSync(path.dirname(p));
282
- _mkdirpSync(p);
283
- } else {
284
- try {
285
- const stat = fs.statSync(p);
286
- if (!stat.isDirectory()) { throw err0; }
287
- } catch (err1) {
288
- throw err0;
289
- }
290
- }
291
- }
292
- }
293
-
294
- function slashEscape(str) {
295
- const ESCAPE_LOOKUP = {
296
- '\\': 'zB',
297
- ':': 'zC',
298
- '/': 'zS',
299
- '\x00': 'z0',
300
- 'z': 'zZ',
301
- };
302
- const ESCAPE_REGEX = /[\\:/\x00z]/g; // eslint-disable-line no-control-regex
303
- return str.replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]);
304
- }
305
-
306
- function supportsCachedData() {
307
- const script = new vm.Script('""', {produceCachedData: true});
308
- // chakracore, as of v1.7.1.0, returns `false`.
309
- return script.cachedDataProduced === true;
310
- }
311
-
312
- function getCacheDir() {
313
- const v8_compile_cache_cache_dir = process.env.V8_COMPILE_CACHE_CACHE_DIR;
314
- if (v8_compile_cache_cache_dir) {
315
- return v8_compile_cache_cache_dir;
316
- }
317
-
318
- // Avoid cache ownership issues on POSIX systems.
319
- const dirname = typeof process.getuid === 'function'
320
- ? 'v8-compile-cache-' + process.getuid()
321
- : 'v8-compile-cache';
322
- // Avoid cache incompatibility issues with Rosetta on Apple Silicon.
323
- const arch = process.arch;
324
- const version = typeof process.versions.v8 === 'string'
325
- ? process.versions.v8
326
- : typeof process.versions.chakracore === 'string'
327
- ? 'chakracore-' + process.versions.chakracore
328
- : 'node-' + process.version;
329
- const cacheDir = path.join(os.tmpdir(), dirname, arch, version);
330
- return cacheDir;
331
- }
332
-
333
- function getMainName() {
334
- // `require.main.filename` is undefined or null when:
335
- // * node -e 'require("v8-compile-cache")'
336
- // * node -r 'v8-compile-cache'
337
- // * Or, requiring from the REPL.
338
- const mainName = require.main && typeof require.main.filename === 'string'
339
- ? require.main.filename
340
- : process.cwd();
341
- return mainName;
342
- }
343
-
344
- //------------------------------------------------------------------------------
345
- // main
346
- //------------------------------------------------------------------------------
347
-
348
- if (!process.env.DISABLE_V8_COMPILE_CACHE && supportsCachedData()) {
349
- const cacheDir = getCacheDir();
350
- const prefix = getMainName();
351
- const blobStore = new FileSystemBlobStore(cacheDir, prefix);
352
-
353
- const nativeCompileCache = new NativeCompileCache();
354
- nativeCompileCache.setCacheStore(blobStore);
355
- nativeCompileCache.install();
356
-
357
- process.once('exit', () => {
358
- if (blobStore.isDirty()) {
359
- blobStore.save();
360
- }
361
- nativeCompileCache.uninstall();
362
- });
363
- }
364
-
365
- module.exports.__TEST__ = {
366
- FileSystemBlobStore,
367
- NativeCompileCache,
368
- mkdirpSync,
369
- slashEscape,
370
- supportsCachedData,
371
- getCacheDir,
372
- getMainName,
373
- };