🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

tsxx

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsxx - npm Package Compare versions

Comparing version
1.0.11
to
1.0.12
+6
dist/test/glob/package.json
{
"hmrGlobs": [
"src/**/*.js",
"src/**/*.ts"
]
}
+18
-5

@@ -19,3 +19,3 @@ /**

const loaded = oldLoad.call(this, request, parent, isMain);
if (parent && !/node_modules/.test(parent.filename) && !/package\\tsxx\\/.test(parent.filename)) {
if (parent) {
const { filename, children } = parent;

@@ -52,3 +52,6 @@ if (!aliveFilenames.includes(filename)) {

delete relationModuleFilenames[filename];
aliveFilenames.splice(aliveFilenames.indexOf(filename), 1);
const aliveIndex = aliveFilenames.indexOf(filename);
if (aliveIndex !== -1) {
aliveFilenames.splice(aliveIndex, 1);
}
for (const parentFilename in relationModuleFilenames) {

@@ -62,3 +65,5 @@ const developFilenames = relationModuleFilenames[parentFilename];

const { Debounce } = require('./util.js');
const { Debounce, getPackageGlobHmrFiles } = require('./util.js');
const globHmrFiles = getPackageGlobHmrFiles();
const { hookServices, unblocks } = require('./hmr-hook.js');

@@ -82,6 +87,14 @@ hookServices();

const chokidar = require('chokidar');
chokidar.watch(process.cwd()).on('change', freshFilename => {
if (aliveFilenames.includes(freshFilename)) {
const chokidarWatcher = chokidar.watch(process.cwd());
chokidarWatcher.on('change', freshFilename => {
if (aliveFilenames.includes(freshFilename) || globHmrFiles.includes(freshFilename)) {
debouncedFunc.call(freshFilename);
}
});
chokidarWatcher.on('add', freshFilename => {
const newGlobHmrFiles = getPackageGlobHmrFiles();
if (!globHmrFiles.includes(freshFilename) && newGlobHmrFiles.includes(freshFilename)) {
globHmrFiles.push(freshFilename);
}
});
const url = require('url');
const path = require('path');
const loaders = ['./hmr.mjs', './loaders/loader-block.mjs'];

@@ -22,2 +23,27 @@ const getLoaderUrl = loader => url.pathToFileURL(require.resolve(loader)).toString();

const getPackageGlobHmrFiles = (cwd = undefined) => {
if (!cwd) {
cwd = process.cwd();
}
const packageJson = path.join(cwd, 'package.json');
/**
* @type {Record<string, any>}
*/
const packageJsonObj = require(packageJson);
/**
* @type {string[]}
*/
const hmrGlobs = packageJsonObj.hmrGlobs || [];
const hmrFiles = [];
if (hmrGlobs.length) {
const { globSync } = require('glob');
const globFiles = globSync(hmrGlobs, { cwd, ignore: 'node_modules/**' });
for (const globFile of globFiles) {
const fullPath = path.join(cwd, globFile);
hmrFiles.push(fullPath);
}
}
return hmrFiles;
};
class Debounce {

@@ -45,1 +71,3 @@ constructor(func, delay) {

module.exports.getLoaderArgs = getLoaderArgs;
module.exports.getPackageGlobHmrFiles = getPackageGlobHmrFiles;
import { test, expect } from 'vitest';
// @ts-ignore
import { getSpawnArgs, Debounce, getLoaderArgs } from './util.js';
import { getSpawnArgs, Debounce, getLoaderArgs, getPackageGlobHmrFiles } from './util.js';
import * as path from 'path';
test('get package glob hmr files', () => {
let cwd = path.join(process.cwd(), 'src/test/glob');
const files = getPackageGlobHmrFiles(cwd);
expect(files).toEqual([
path.join(cwd, 'src/demo03.ts'),
path.join(cwd, 'src/demo02.js'),
path.join(cwd, 'src/demo01.js')
]);
});
test('get new spawn args', () => {

@@ -6,0 +17,0 @@ const loaderArgs = getLoaderArgs();

{
"name": "tsxx",
"version": "1.0.11",
"version": "1.0.12",
"description": "tsx 增强",
"scripts": {
"build": "node build.mjs && cp -r src/* dist/",
"lint": "prettier --write ."
"lint": "prettier --write .",
"test": "vitest"
},

@@ -19,4 +20,5 @@ "files": [

"chokidar": "^3.5.3",
"glob": "^10.3.4",
"tsx": "^3.12.8"
}
}