New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

file-lane

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-lane - npm Package Compare versions

Comparing version 2.0.1-alpha.12 to 2.0.1-alpha.13

3

lib/FileLane.d.ts

@@ -15,2 +15,3 @@ import IFileLaneConfig from './interface/IFileLaneConfig';

private compilation?;
private ws;
/**

@@ -58,3 +59,3 @@ * 实例化FileLane

/**
* 运行转换后续的任务
* 运行转换初始的任务
*/

@@ -61,0 +62,0 @@ private runPreWorks;

@@ -15,3 +15,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));

@@ -23,2 +22,3 @@ const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));

const path_1 = __importDefault(require("path"));
const ws_1 = __importDefault(require("ws"));
const FileLaneCompilation_1 = __importDefault(require("./FileLaneCompilation"));

@@ -60,7 +60,3 @@ const CompilationEvent_1 = __importDefault(require("./event/CompilationEvent"));

if (errorList && errorList.length) {
ColorConsole_1.default.log({
message: `\r\n${errorList.map((item, index) => `${index + 1}. ${item}`).join('\r\n')}\r\n`,
level: shared_utils_1.LOG_LEVEL.Error,
isOnlyPrintError: true
});
ColorConsole_1.default.error(`### file-lane ### ${errorList.map((item, index) => `${index + 1}. ${item}`).join('\r\n')}`);
return;

@@ -142,14 +138,20 @@ }

this.initCompilation();
yield this.runPreWorks(fileList);
this.triggerPlugins(new CompilationEvent_1.default(CompilationEvent_1.default.PROJECT_START));
for (let item of fileList) {
this.triggerPlugins(new FileEvent_1.default(FileEvent_1.default.FILE_START_COMPILATION, FileLaneUtil_1.default.pathToFileParam(item)));
yield this.buildFile(item);
this.triggerPlugins(new FileEvent_1.default(FileEvent_1.default.FILE_END_COMPILATION, FileLaneUtil_1.default.pathToFileParam(item)));
try {
yield this.runPreWorks(fileList);
this.triggerPlugins(new CompilationEvent_1.default(CompilationEvent_1.default.PROJECT_START));
for (let item of fileList) {
this.triggerPlugins(new FileEvent_1.default(FileEvent_1.default.FILE_START_COMPILATION, FileLaneUtil_1.default.pathToFileParam(item)));
yield this.buildFile(item);
this.triggerPlugins(new FileEvent_1.default(FileEvent_1.default.FILE_END_COMPILATION, FileLaneUtil_1.default.pathToFileParam(item)));
}
this.triggerPlugins(new CompilationEvent_1.default(CompilationEvent_1.default.PROJECT_END));
// 执行extra
this.triggerPlugins(new CompilationEvent_1.default(CompilationEvent_1.default.FLLOW_WORK_START));
yield this.runFollowWorks();
this.triggerPlugins(new CompilationEvent_1.default(CompilationEvent_1.default.FLLOW_WORK_END));
ColorConsole_1.default.success('Success: build finish!');
}
this.triggerPlugins(new CompilationEvent_1.default(CompilationEvent_1.default.PROJECT_END));
// 执行extra
this.triggerPlugins(new CompilationEvent_1.default(CompilationEvent_1.default.FLLOW_WORK_START));
yield this.runFollowWorks();
this.triggerPlugins(new CompilationEvent_1.default(CompilationEvent_1.default.FLLOW_WORK_END));
catch (error) {
ColorConsole_1.default.throw(`ERROR: build error, ${(error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'}`);
}
});

@@ -184,2 +186,14 @@ }

for (let item of loaderList) {
// 转换 result 为 string 或流
result.forEach((fileItem) => {
const { content } = fileItem;
if (content) {
if (!item.raw && typeof content !== 'string') {
fileItem.content = content.toString();
}
else if (item.raw && !(content instanceof Buffer)) {
fileItem.content = Buffer.from(content);
}
}
});
result = yield this.runLoader(result, item);

@@ -200,3 +214,3 @@ }

const outputPath = path_1.default.join(buildPath, resolvePath);
return fs_extra_1.default.outputFile(outputPath, item.content || '', { encoding: 'utf-8' });
return fs_extra_1.default.outputFile(outputPath, Buffer.from(item.content || ''));
}));

@@ -239,3 +253,3 @@ });

/**
* 运行转换后续的任务
* 运行转换初始的任务
*/

@@ -251,3 +265,4 @@ runPreWorks(fileList) {

catch (error) {
// 报错 prework的item error
// prework的item error
ColorConsole_1.default.throw((error === null || error === void 0 ? void 0 : error.toString()) || 'unkonw error');
}

@@ -275,4 +290,12 @@ }

this.listenFileChange(() => __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c;
const fileList = this.collectFile();
if (!this.ws && ((_a = this.compilerOption) === null || _a === void 0 ? void 0 : _a.hasOwnProperty('server'))) {
const port = (_b = this.compilerOption.server) === null || _b === void 0 ? void 0 : _b.port;
this.ws = new ws_1.default(`ws://localhost:${port}`);
}
yield this.build(fileList);
(_c = this.ws) === null || _c === void 0 ? void 0 : _c.send(JSON.stringify({
type: 'restart'
}));
}));

@@ -292,5 +315,3 @@ });

if (FileUtil_1.default.include(filePath, this.config.include, this.config.exclude)) {
ColorConsole_1.default.log({
message: `file change: ${filePath}`
});
ColorConsole_1.default.log(`### file-lane ### file change: ${filePath}`);
files.push(filePath);

@@ -313,3 +334,5 @@ }

listenFileChange(onChange) {
const watcher = chokidar_1.default.watch(this.context.projectPath);
const watcher = chokidar_1.default.watch(this.context.projectPath, {
ignored: this.config.watchIgnores
});
const throttledOnChange = lodash_1.default.throttle(onChange, 1000, {

@@ -328,5 +351,3 @@ leading: true,

.on('ready', () => {
ColorConsole_1.default.log({
message: 'Initial scan complete. Ready for Watch.'
});
ColorConsole_1.default.log(`### file-lane ### Initial scan complete. Ready for Watch.`);
watcher

@@ -348,3 +369,3 @@ .on('add', (path) => {

// 监听错误
ColorConsole_1.default.log({ level: shared_utils_1.LOG_LEVEL.Error, message: error.message });
FileLaneUtil_1.default.checkError(error.message);
});

@@ -351,0 +372,0 @@ if (this.watcher) {

@@ -5,3 +5,5 @@ import { MatchType } from '@aiot-toolkit/shared-utils/lib/utils/FileUtil';

import IPlugin from './IPlugin';
export type ILoaderClass = new (...args: any[]) => ILoader;
export type ILoaderClass = (new (...args: any[]) => ILoader) & {
raw?: boolean;
};
/**

@@ -81,4 +83,8 @@ * IFileLaneConfig

followWorks?: FollowWork<O>[];
/**
* 配置watch时忽略的文件或者文件夹
*/
watchIgnores?: MatchType;
}
export type FollowWork<O = any> = (context: IFileLaneContext, config?: IFileLaneConfig, compilerOption?: O) => Promise<any>;
export type PreWork<O = any> = (context: IFileLaneContext, fileList: string[], config: IFileLaneConfig, compilerOption?: O) => Promise<any>;

@@ -0,1 +1,2 @@

/// <reference types="node" />
/**

@@ -6,3 +7,3 @@ * IFileParam

path: string;
content?: string;
content?: string | Buffer;
/**

@@ -9,0 +10,0 @@ * 额外的内容,例如 sourceMap,位置映射列表等

@@ -22,3 +22,4 @@ import IFileLaneContext from '../interface/IFileLaneContext';

static createContext(output: string, projectPath?: string): IFileLaneContext;
static checkError(message: string): void;
}
export default FileLaneUtil;

@@ -35,3 +35,3 @@ "use strict";

if (stats.isFile()) {
content = fs_extra_1.default.readFileSync(path, 'utf-8');
content = fs_extra_1.default.readFileSync(path);
}

@@ -59,6 +59,3 @@ }

archive.on('error', (err) => {
ColorConsole_1.default.log({
level: shared_utils_1.LOG_LEVEL.Error,
message: err.message
});
ColorConsole_1.default.throw(`${err.message}`);
reject();

@@ -68,5 +65,6 @@ });

output.on('open', () => {
ColorConsole_1.default.log({ message: `写入流已打开` });
ColorConsole_1.default.info(`Write stream is open`);
});
output.on('close', () => {
ColorConsole_1.default.info(`Write stream is closed`);
resolve();

@@ -99,2 +97,13 @@ });

}
static checkError(message) {
if (message.includes('System limit for number of file watchers reached')) {
ColorConsole_1.default.error('There are too many files to watch, ', {
word: 'please configure the content to be ignored.',
style: {
bgColor: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Error).color || '#FF0000'
}
}, '(For example, node_modules)');
}
ColorConsole_1.default.throw(`### file-lane ### watch error ${message}`);
}
}

@@ -101,0 +110,0 @@ exports.default = FileLaneUtil;

{
"name": "file-lane",
"version": "2.0.1-alpha.12",
"version": "2.0.1-alpha.13",
"description": "File conversion tool, can be one-to-one, one to N, N to one",

@@ -28,3 +28,3 @@ "keywords": [

"dependencies": {
"@aiot-toolkit/shared-utils": "2.0.1-alpha.12",
"@aiot-toolkit/shared-utils": "2.0.1-alpha.13",
"archiver": "^6.0.1",

@@ -37,3 +37,3 @@ "chokidar": "^3.5.3",

},
"gitHead": "1d1840ffc4a8e32c7a097c7335c226285bfba95f"
"gitHead": "49040b26a267943df4d0b202b200d4df5bcbc1ef"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc