From 7c4dcf1ff4fcb3c122be555facb157d7a94f871a Mon Sep 17 00:00:00 2001 From: skydog221 Date: Tue, 26 Aug 2025 20:54:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8Dchalk-template?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=E7=BC=96=E8=AF=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -移除chalk-template,改为使用chalk --- package.json | 3 +- src/native/plugins.ts | 117 ++++++++++++++++++++++++++---------------- tsconfig.json | 79 ++++++++++------------------ yarn.lock | 12 ----- 4 files changed, 102 insertions(+), 109 deletions(-) diff --git a/package.json b/package.json index 0c7b21f..ee3f5b1 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,6 @@ }, "dependencies": { "chalk": "4", - "chalk-template": "^1.1.0", "clipcc-extension": "^0.2.0" } -} \ No newline at end of file +} diff --git a/src/native/plugins.ts b/src/native/plugins.ts index 1519bdf..4df1dd4 100644 --- a/src/native/plugins.ts +++ b/src/native/plugins.ts @@ -1,49 +1,78 @@ -import { Linter } from 'eslint'; -import fs from 'fs'; -import { ExtendWebpackConfig, NativePlugin } from './structs/plugin'; -import path from 'path'; -import { Configuration } from 'webpack'; -import chalkTemplate from 'chalk-template'; +import { Linter } from "eslint"; +import fs from "fs"; +import { ExtendWebpackConfig, NativePlugin } from "./structs/plugin"; +import path from "path"; +import { Configuration } from "webpack"; +import chalk from "chalk"; export function load() { - console.log(`Mode: ${process.env.NODE_ENV === 'production' ? 'production' : 'development'}`); - const disablePlugins = JSON.parse(fs.readFileSync(path.join(__dirname, '../../plugins/disable.json'), 'utf-8')) as Record<'platform' | 'folder', string[]>; - const webpack: Record Configuration> = {}; - const eslint: Linter.Config[] = []; - const pluginsDir = path.join(__dirname, '../../plugins'); - const pluginFolders = fs.readdirSync(pluginsDir) - .filter(file => fs.statSync(path.join(pluginsDir, file)).isDirectory()); - const pluginIds: string[] = []; - function pad(id: string) { - return id.padEnd(Math.max(...pluginIds.map(id => id.length)), ' '); + console.log( + `Mode: ${ + process.env.NODE_ENV === "production" ? "production" : "development" + }` + ); + const disablePlugins = JSON.parse( + fs.readFileSync(path.join(__dirname, "../../plugins/disable.json"), "utf-8") + ) as Record<"platform" | "folder", string[]>; + const webpack: Record< + string, + (config: ExtendWebpackConfig) => Configuration + > = {}; + const eslint: Linter.Config[] = []; + const pluginsDir = path.join(__dirname, "../../plugins"); + const pluginFolders = fs + .readdirSync(pluginsDir) + .filter((file) => fs.statSync(path.join(pluginsDir, file)).isDirectory()); + const pluginIds: string[] = []; + function pad(id: string) { + return id.padEnd(Math.max(...pluginIds.map((id) => id.length)), " "); + } + for (const folder of pluginFolders) { + pluginIds.push(folder); + } + for (const folder of pluginFolders) { + const currentNativeId = folder; + if (disablePlugins.folder.includes(currentNativeId)) { + console.log( + `${chalk.gray(pad(currentNativeId))} | ${chalk.red("DISABLED")}` + ); + continue; } - for (const folder of pluginFolders) { - pluginIds.push(folder); - } - for (const folder of pluginFolders) { - const currentNativeId = folder; - if (disablePlugins.folder.includes(currentNativeId)) { - console.log(chalkTemplate`{gray ${pad(currentNativeId)}} | {red DISABLED}`); - continue; - } - try { - const nativePath = path.resolve('dist/native/plugins', folder, 'native.js'); - if (fs.existsSync(nativePath)) { - const { default: plugin }: { default: NativePlugin } = require(nativePath); - if (disablePlugins.platform.includes(plugin.platform)) { - console.log(chalkTemplate`{gray ${pad(plugin.platform)}} | {red DISABLED}`); - continue; - } - webpack[currentNativeId] = plugin.configureWebpack?.call(plugin) ?? (() => ({})); - eslint.push(...(plugin.configureESLint?.call(plugin) ?? [])); - console.log(chalkTemplate`{gray ${pad(currentNativeId)}} | {green loaded successfully}: {cyan ${plugin.platform}}.`); - } else { - webpack[currentNativeId] = () => ({}); - console.warn(chalkTemplate`{gray ${pad(currentNativeId)}} | {yellow not found native module}.`); - } - } catch (err) { - console.error(chalkTemplate`{gray ${pad(currentNativeId)}} | {red ${err}}`); + try { + const nativePath = path.resolve( + "dist/native/plugins", + folder, + "native.js" + ); + if (fs.existsSync(nativePath)) { + const { + default: plugin, + }: { default: NativePlugin } = require(nativePath); + if (disablePlugins.platform.includes(plugin.platform)) { + console.log( + `${chalk.gray(pad(plugin.platform))} | ${chalk.red("DISABLED")}` + ); + continue; } + webpack[currentNativeId] = + plugin.configureWebpack?.call(plugin) ?? (() => ({})); + eslint.push(...(plugin.configureESLint?.call(plugin) ?? [])); + console.log( + `${chalk.gray(pad(currentNativeId))} | ${chalk.green( + "loaded successfully" + )}: ${chalk.cyan(plugin.platform)}.` + ); + } else { + webpack[currentNativeId] = () => ({}); + console.warn( + `${chalk.gray(pad(currentNativeId))} | ${chalk.yellow( + "not found native module" + )}.` + ); + } + } catch (err) { + console.error(`${chalk.gray(pad(currentNativeId))} | ${chalk.red(err)}`); } - return { webpack, eslint }; -} \ No newline at end of file + } + return { webpack, eslint }; +} diff --git a/tsconfig.json b/tsconfig.json index d377a34..68404a1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,52 +1,29 @@ { - "compilerOptions": { - "target": "ESNext", - "module": "commonjs", - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "skipLibCheck": true, - "experimentalDecorators": true, - "moduleResolution": "node", - "allowJs": true, - "checkJs": true, - "isolatedModules": true, - "resolveJsonModule": true, - "typeRoots": [ - "node_modules/@types", - "node_modules/@turbowarp/types" - ], - "types": [ - "webpack-env", - "node", - "index.d.ts" - ], - "baseUrl": ".", - "outDir": "dist/native", - "paths": { - "fs-context": [ - "src/fs-context/index" - ], - "package.json": [ - "package.json" - ], - "fs-context/*": [ - "src/fs-context/*" - ], - "@/*": [ - "src/extension/*" - ], - "@sample/*": [ - "src/fs-context/samples/*" - ], - "@plugin/*": [ - "plugins/*" - ] - } - }, - "include": [ - "src/**/*.ts", - "plugins/**/*.ts", - "plugins/disable.json" - ] -} \ No newline at end of file + "compilerOptions": { + "target": "ESNext", + "module": "commonjs", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "experimentalDecorators": true, + "moduleResolution": "node", + "allowJs": true, + "checkJs": true, + "isolatedModules": true, + "resolveJsonModule": true, + "typeRoots": ["node_modules/@types", "node_modules/@turbowarp/types"], + "types": ["webpack-env", "node", "index.d.ts"], + "baseUrl": ".", + "outDir": "dist/native", + "paths": { + "fs-context": ["src/fs-context/index"], + "package.json": ["package.json"], + "fs-context/*": ["src/fs-context/*"], + "@/*": ["src/extension/*"], + "@sample/*": ["src/fs-context/samples/*"], + "@plugin/*": ["plugins/*"] + } + }, + "include": ["src/**/*.ts", "plugins/**/*.ts", "plugins/disable.json"] +} diff --git a/yarn.lock b/yarn.lock index 33403c0..e27d86b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1107,13 +1107,6 @@ caniuse-lite@^1.0.30001726: resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001733.tgz#918405ed6647a62840fb328832cf5a03f986974b" integrity sha512-e4QKw/O2Kavj2VQTKZWrwzkt3IxOmIlU6ajRb6LP64LHpBo1J67k2Hi4Vu/TgJWsNtynurfS0uK3MaUTCPfu5Q== -chalk-template@^1.1.0: - version "1.1.0" - resolved "https://registry.npmjs.org/chalk-template/-/chalk-template-1.1.0.tgz#ffc55db6dd745e9394b85327c8ac8466edb7a7b1" - integrity sha512-T2VJbcDuZQ0Tb2EWwSotMPJjgpy1/tGee1BTpUNsGZ/qgNjV2t7Mvu+d4600U564nbLesN1x2dPL+xii174Ekg== - dependencies: - chalk "^5.2.0" - chalk@4, chalk@^4.0.0, chalk@^4.1.0: version "4.1.2" resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" @@ -1131,11 +1124,6 @@ chalk@^2.4.1: escape-string-regexp "^1.0.5" supports-color "^5.3.0" -chalk@^5.2.0: - version "5.5.0" - resolved "https://registry.npmjs.org/chalk/-/chalk-5.5.0.tgz#67ada1df5ca809dc84c9b819d76418ddcf128428" - integrity sha512-1tm8DTaJhPBG3bIkVeZt1iZM9GfSX2lzOeDVZH9R9ffRHpmHvxZ/QhgQH/aDTkswQVt+YHdXAdS/In/30OjCbg== - chokidar@^3.6.0: version "3.6.0" resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz#197c6cc669ef2a8dc5e7b4d97ee4e092c3eb0d5b" From d6a748244bd3c98b8c8667648cea1f3d275907a1 Mon Sep 17 00:00:00 2001 From: skydog221 Date: Tue, 26 Aug 2025 20:55:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:webpack-dev-server=E6=B7=BB=E5=8A=A0cor?= =?UTF-8?q?s=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webpack.config.js | 158 +++++++++++++++++++++++++--------------------- 1 file changed, 85 insertions(+), 73 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index a84e99d..ed36f45 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,78 +1,90 @@ -const path = require('path'); -const webpack = require('webpack'); +const path = require("path"); +const webpack = require("webpack"); -const Webpackbar = require('webpackbar'); +const Webpackbar = require("webpackbar"); -const tsconfigJson = require('./tsconfig.json'); -const packageJson = require('./package.json'); -const { merge } = require('webpack-merge'); +const tsconfigJson = require("./tsconfig.json"); +const packageJson = require("./package.json"); +const { merge } = require("webpack-merge"); module.exports = () => { - const { webpack: webpackConfig } = require('./dist/native/src/native/plugins').load(); - return packageJson.extension.platform.map((platform) => { - const filename = `[${platform}]${packageJson.extension.id}@${packageJson.extension.version}.js`; - const base = { - name: platform, - entry: 'fs-context/entry.ts', - resolve: { - extensions: ['.js', '.ts'], - alias: Object.fromEntries( - Object.entries(tsconfigJson.compilerOptions.paths) - .map(([key, value]) => [key.replace('/*', ''), path.resolve(__dirname, value[0].replace('/*', ''))]) - ) - }, - output: { - path: path.resolve(__dirname, 'dist'), - filename - }, - module: { - rules: [ - { - test: /\.ts$/i, - use: 'ts-loader', - exclude: /node_modules/ - } - ] - }, - plugins: [ - new Webpackbar({ - name: packageJson.extension.name.toUpperCase(), - color: 'green' - }), - new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }), - new webpack.DefinePlugin({ - fsContext: JSON.stringify({ - platform, - developing: process.env.NODE_ENV === 'development', - extension: packageJson.extension - }) - }) - ], - /** - * @type {import('webpack-dev-server').Configuration} - */ - devServer: { - port: 7777, - setupExitSignals: false, - webSocketServer: false, - client: { - logging: 'none' - }, - setupMiddlewares(mw, server) { - server.app.get('/', (_, res) => { - res.redirect(`/${filename}`); - }); - return mw; - }, - allowedHosts: 'all' - }, - mode: process.env.NODE_ENV, - stats: 'errors-warnings' - }; - return merge(base, webpackConfig[platform]({ filename, base }) ?? {}, { - plugins: [ - //pass + const { webpack: webpackConfig } = + require("./dist/native/src/native/plugins").load(); + return packageJson.extension.platform.map((platform) => { + const filename = `[${platform}]${packageJson.extension.id}@${packageJson.extension.version}.js`; + const base = { + name: platform, + entry: "fs-context/entry.ts", + resolve: { + extensions: [".js", ".ts"], + alias: Object.fromEntries( + Object.entries(tsconfigJson.compilerOptions.paths).map( + ([key, value]) => [ + key.replace("/*", ""), + path.resolve(__dirname, value[0].replace("/*", "")), ] - }); - }) -}; \ No newline at end of file + ) + ), + }, + output: { + path: path.resolve(__dirname, "dist"), + filename, + }, + module: { + rules: [ + { + test: /\.ts$/i, + use: "ts-loader", + exclude: /node_modules/, + }, + ], + }, + plugins: [ + new Webpackbar({ + name: packageJson.extension.name.toUpperCase(), + color: "green", + }), + new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }), + new webpack.DefinePlugin({ + fsContext: JSON.stringify({ + platform, + developing: process.env.NODE_ENV === "development", + extension: packageJson.extension, + }), + }), + ], + /** + * @type {import('webpack-dev-server').Configuration} + */ + devServer: { + port: 7777, + setupExitSignals: false, + webSocketServer: false, + client: { + logging: "none", + }, + setupMiddlewares(mw, server) { + server.app.get("/", (_, res) => { + res.redirect(`/${filename}`); + }); + return mw; + }, + allowedHosts: "all", + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": + "GET, POST, PUT, DELETE, PATCH, OPTIONS", + "Access-Control-Allow-Headers": + "X-Requested-With, content-type, Authorization", + }, + }, + mode: process.env.NODE_ENV, + stats: "errors-warnings", + }; + return merge(base, webpackConfig[platform]({ filename, base }) ?? {}, { + plugins: [ + //pass + ], + }); + }); +};