@atls/code-service 0.0.6 → 0.0.11

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/dist/index.js CHANGED
@@ -10,5 +10,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./build"), exports);
14
- __exportStar(require("./watch"), exports);
13
+ __exportStar(require("./webpack.config"), exports);
14
+ __exportStar(require("./service"), exports);
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Service = void 0;
7
+ const node_stream_1 = require("node:stream");
8
+ const webpack_1 = __importDefault(require("webpack"));
9
+ const webpack_start_server_plugin_1 = require("@atls/webpack-start-server-plugin");
10
+ const webpack_config_1 = require("./webpack.config");
11
+ class Service {
12
+ constructor(cwd) {
13
+ this.cwd = cwd;
14
+ }
15
+ async build(plugins = []) {
16
+ const config = new webpack_config_1.WebpackConfig(this.cwd);
17
+ const compiler = (0, webpack_1.default)(await config.build());
18
+ return new Promise((resolve, reject) => {
19
+ compiler.run((error, stats) => {
20
+ if (error) {
21
+ if (!error.message) {
22
+ reject(error);
23
+ }
24
+ else {
25
+ resolve({
26
+ errors: [{ message: error.message }],
27
+ warnings: [],
28
+ });
29
+ }
30
+ }
31
+ else if (stats) {
32
+ const { errors = [], warnings = [] } = stats.toJson();
33
+ resolve({
34
+ errors: errors.map((error) => ({ message: error.message })),
35
+ warnings: warnings.map((warning) => ({ message: warning.message })),
36
+ });
37
+ }
38
+ else {
39
+ resolve({
40
+ errors: [],
41
+ warnings: [],
42
+ });
43
+ }
44
+ });
45
+ });
46
+ }
47
+ async watch(callback) {
48
+ const config = new webpack_config_1.WebpackConfig(this.cwd);
49
+ const pass = new node_stream_1.PassThrough();
50
+ pass.on('data', (chunk) => {
51
+ chunk
52
+ .toString()
53
+ .split(/\r?\n/)
54
+ .filter(Boolean)
55
+ .forEach((row) => {
56
+ try {
57
+ callback(JSON.parse(row));
58
+ }
59
+ catch {
60
+ callback({ body: row });
61
+ }
62
+ });
63
+ });
64
+ return (0, webpack_1.default)(await config.build('development', [
65
+ {
66
+ name: 'start-server',
67
+ use: webpack_start_server_plugin_1.StartServerPlugin,
68
+ args: [
69
+ {
70
+ stdout: pass,
71
+ stderr: pass,
72
+ },
73
+ ],
74
+ },
75
+ ])).watch({}, (error, stats) => {
76
+ if (error) {
77
+ callback({
78
+ severityText: 'ERROR',
79
+ body: error.message || error,
80
+ });
81
+ }
82
+ else if (stats) {
83
+ const { errors = [], warnings = [] } = stats.toJson();
84
+ warnings.forEach((warning) => callback({
85
+ severityText: 'WARN',
86
+ body: warning.message,
87
+ }));
88
+ errors.forEach((err) => callback({
89
+ severityText: 'ERROR',
90
+ body: err.message,
91
+ }));
92
+ }
93
+ });
94
+ }
95
+ }
96
+ exports.Service = Service;
@@ -47,10 +47,10 @@ exports.unusedExternals = [
47
47
  'next',
48
48
  ];
49
49
  const getUnpluggedDependencies = async () => {
50
- const configuration = await core_1.Configuration.find(process.cwd(), cli_1.getPluginConfiguration());
50
+ const configuration = await core_1.Configuration.find(process.cwd(), (0, cli_1.getPluginConfiguration)());
51
51
  const pnpUnpluggedFolder = configuration.get('pnpUnpluggedFolder');
52
52
  const dependenciesNames = new Set();
53
- const entries = await fast_glob_1.default('*/node_modules/*/package.json', {
53
+ const entries = await (0, fast_glob_1.default)('*/node_modules/*/package.json', {
54
54
  cwd: pnpUnpluggedFolder,
55
55
  });
56
56
  await Promise.all(entries
@@ -62,18 +62,17 @@ const getUnpluggedDependencies = async () => {
62
62
  dependenciesNames.add(name);
63
63
  }
64
64
  }
65
- catch (_a) { }
65
+ catch { }
66
66
  }));
67
67
  return dependenciesNames;
68
68
  };
69
69
  exports.getUnpluggedDependencies = getUnpluggedDependencies;
70
70
  const getExternals = async (cwd) => {
71
- var _a, _b;
72
- const configuration = await core_1.Configuration.find(process.cwd(), cli_1.getPluginConfiguration());
71
+ const configuration = await core_1.Configuration.find(process.cwd(), (0, cli_1.getPluginConfiguration)());
73
72
  const { project } = await core_2.Project.find(configuration, process.cwd());
74
73
  const workspace = project.getWorkspaceByFilePath(cwd);
75
- const workspaceExternals = Object.keys(((_b = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.manifest) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.externalDependencies) || {});
76
- const unpluggedExternals = Array.from(await exports.getUnpluggedDependencies());
74
+ const workspaceExternals = Object.keys(workspace?.manifest?.raw?.externalDependencies || {});
75
+ const unpluggedExternals = Array.from(await (0, exports.getUnpluggedDependencies)());
77
76
  return Array.from(new Set([...workspaceExternals, ...unpluggedExternals, ...exports.unusedExternals]));
78
77
  };
79
78
  exports.getExternals = getExternals;
@@ -5,10 +5,9 @@ const core_1 = require("@yarnpkg/core");
5
5
  const core_2 = require("@yarnpkg/core");
6
6
  const cli_1 = require("@yarnpkg/cli");
7
7
  const getResolveAliases = async (cwd) => {
8
- var _a, _b, _c;
9
- const configuration = await core_1.Configuration.find(process.cwd(), cli_1.getPluginConfiguration());
8
+ const configuration = await core_1.Configuration.find(process.cwd(), (0, cli_1.getPluginConfiguration)());
10
9
  const { project } = await core_2.Project.find(configuration, process.cwd());
11
10
  const workspace = project.getWorkspaceByFilePath(cwd);
12
- return ((_c = (_b = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.manifest) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.resolve) === null || _c === void 0 ? void 0 : _c.alias) || [];
11
+ return workspace?.manifest?.raw?.resolve?.alias || [];
13
12
  };
14
13
  exports.getResolveAliases = getResolveAliases;
@@ -4,14 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createWebpackConfig = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
7
8
  const webpack_chain_1 = __importDefault(require("webpack-chain"));
8
- const path_1 = __importDefault(require("path"));
9
9
  const webpack_1 = __importDefault(require("webpack"));
10
- const code_typescript_1 = require("@atls/code-typescript");
10
+ const config_typescript_1 = __importDefault(require("@atls/config-typescript"));
11
11
  const externals_1 = require("./externals");
12
12
  const resolve_1 = require("./resolve");
13
13
  const createWebpackConfig = async (cwd, environment, plugins = []) => {
14
- const externals = (await externals_1.getExternals(cwd)).reduce((result, dependency) => (Object.assign(Object.assign({}, result), { [dependency]: `commonjs2 ${dependency}` })), {});
14
+ const externals = (await (0, externals_1.getExternals)(cwd)).reduce((result, dependency) => ({
15
+ ...result,
16
+ [dependency]: `commonjs2 ${dependency}`,
17
+ }), {});
15
18
  const config = new webpack_chain_1.default();
16
19
  config
17
20
  .mode(environment)
@@ -19,10 +22,10 @@ const createWebpackConfig = async (cwd, environment, plugins = []) => {
19
22
  .target('async-node')
20
23
  .optimization.minimize(false);
21
24
  config.node.set('__dirname', false).set('__filename', false);
22
- config.entry('index').add(path_1.default.join(cwd, 'src/index'));
23
- config.output.path(path_1.default.join(cwd, 'dist')).filename('[name].js');
25
+ config.entry('index').add(node_path_1.default.join(cwd, 'src/index'));
26
+ config.output.path(node_path_1.default.join(cwd, 'dist')).filename('[name].js');
24
27
  config.resolve.extensions.add('.tsx').add('.ts').add('.js');
25
- const aliases = await resolve_1.getResolveAliases(cwd);
28
+ const aliases = await (0, resolve_1.getResolveAliases)(cwd);
26
29
  aliases.forEach((target) => {
27
30
  config.resolve.alias.set(target, require.resolve(target, { paths: [cwd] }));
28
31
  });
@@ -41,8 +44,8 @@ const createWebpackConfig = async (cwd, environment, plugins = []) => {
41
44
  .options({
42
45
  transpileOnly: true,
43
46
  experimentalWatchApi: true,
44
- compilerOptions: Object.assign(Object.assign({}, code_typescript_1.base.compilerOptions), { sourceMap: true }),
45
- configFile: path_1.default.join(__dirname, '../../tsconfig.stub.json'),
47
+ compilerOptions: { ...config_typescript_1.default.compilerOptions, sourceMap: true },
48
+ configFile: node_path_1.default.join(__dirname, '../../tsconfig.stub.json'),
46
49
  });
47
50
  config.module
48
51
  .rule('protos')
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WebpackConfig = void 0;
7
+ const promises_1 = require("node:fs/promises");
8
+ const node_path_1 = require("node:path");
9
+ const core_1 = require("@yarnpkg/core");
10
+ const core_2 = require("@yarnpkg/core");
11
+ const cli_1 = require("@yarnpkg/cli");
12
+ const webpack_chain_1 = __importDefault(require("webpack-chain"));
13
+ const fast_glob_1 = __importDefault(require("fast-glob"));
14
+ const webpack_1 = require("webpack");
15
+ const config_typescript_1 = __importDefault(require("@atls/config-typescript"));
16
+ const webpack_externals_1 = require("./webpack.externals");
17
+ const webpack_externals_2 = require("./webpack.externals");
18
+ class WebpackConfig {
19
+ constructor(cwd) {
20
+ this.cwd = cwd;
21
+ }
22
+ async build(environment = 'production', plugins = []) {
23
+ const root = process.cwd();
24
+ const configuration = await core_1.Configuration.find(root, (0, cli_1.getPluginConfiguration)());
25
+ const { project } = await core_2.Project.find(configuration, root);
26
+ const config = new webpack_chain_1.default();
27
+ this.applyCommon(config, environment);
28
+ this.applyPlugins(config, environment);
29
+ this.applyModules(config);
30
+ config.externals(await this.getExternals(configuration, project));
31
+ plugins.forEach((plugin) => {
32
+ config.plugin(plugin.name).use(plugin.use, plugin.args);
33
+ });
34
+ return config.toConfig();
35
+ }
36
+ applyCommon(config, environment) {
37
+ config
38
+ .mode(environment)
39
+ .bail(environment === 'production')
40
+ .target('async-node')
41
+ .optimization.minimize(false);
42
+ config.node.set('__dirname', false).set('__filename', false);
43
+ config.entry('index').add((0, node_path_1.join)(this.cwd, 'src/index'));
44
+ config.output.path((0, node_path_1.join)(this.cwd, 'dist')).filename('[name].js');
45
+ config.resolve.extensions.add('.tsx').add('.ts').add('.js');
46
+ config.devtool(environment === 'production' ? 'source-map' : 'eval-cheap-module-source-map');
47
+ }
48
+ applyPlugins(config, environment) {
49
+ config.when(environment === 'development', () => {
50
+ config.plugin('hot').use(webpack_1.HotModuleReplacementPlugin);
51
+ });
52
+ }
53
+ applyModules(config) {
54
+ config.module
55
+ .rule('ts')
56
+ .test(/.tsx?$/)
57
+ .use('ts')
58
+ .loader(require.resolve('ts-loader'))
59
+ .options({
60
+ transpileOnly: true,
61
+ experimentalWatchApi: true,
62
+ onlyCompileBundledFiles: true,
63
+ compilerOptions: { ...config_typescript_1.default.compilerOptions, sourceMap: true },
64
+ });
65
+ config.module
66
+ .rule('protos')
67
+ .test(/\.proto$/)
68
+ .use('proto')
69
+ .loader(require.resolve('@atls/webpack-proto-imports-loader'));
70
+ }
71
+ async getUnpluggedDependencies(configuration) {
72
+ const pnpUnpluggedFolder = configuration.get('pnpUnpluggedFolder');
73
+ const dependenciesNames = new Set();
74
+ const entries = await (0, fast_glob_1.default)('*/node_modules/*/package.json', {
75
+ cwd: pnpUnpluggedFolder,
76
+ });
77
+ await Promise.all(entries
78
+ .map((entry) => (0, node_path_1.join)(pnpUnpluggedFolder, entry))
79
+ .map(async (entry) => {
80
+ try {
81
+ const { name } = JSON.parse((await (0, promises_1.readFile)(entry)).toString());
82
+ if (name && !webpack_externals_1.FORCE_UNPLUGGED_PACKAGES.has(name)) {
83
+ dependenciesNames.add(name);
84
+ }
85
+ }
86
+ catch { }
87
+ }));
88
+ return dependenciesNames;
89
+ }
90
+ async getExternals(configuration, project) {
91
+ const workspace = project.getWorkspaceByFilePath(this.cwd);
92
+ const workspaceExternals = Object.keys(workspace?.manifest?.raw?.externalDependencies || {});
93
+ const unpluggedExternals = Array.from(await this.getUnpluggedDependencies(configuration));
94
+ return Array.from(new Set([...workspaceExternals, ...unpluggedExternals, ...webpack_externals_2.UNUSED_EXTERNALS])).reduce((result, dependency) => ({
95
+ ...result,
96
+ [dependency]: `commonjs2 ${dependency}`,
97
+ }), {});
98
+ }
99
+ }
100
+ exports.WebpackConfig = WebpackConfig;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNUSED_EXTERNALS = exports.FORCE_UNPLUGGED_PACKAGES = void 0;
4
+ exports.FORCE_UNPLUGGED_PACKAGES = new Set([
5
+ 'nan',
6
+ 'node-gyp',
7
+ 'node-pre-gyp',
8
+ 'node-addon-api',
9
+ 'fsevents',
10
+ 'core-js',
11
+ 'core-js-pure',
12
+ 'protobufjs',
13
+ ]);
14
+ exports.UNUSED_EXTERNALS = [
15
+ 'cli-color',
16
+ 'flaschenpost',
17
+ 'amqp-connection-manager',
18
+ 'kafkajs',
19
+ 'amqplib',
20
+ 'redis',
21
+ 'mqtt',
22
+ 'nats',
23
+ '@nestjs/websockets',
24
+ 'typeorm-aurora-data-api-driver',
25
+ 'react-native-sqlite-storage',
26
+ '@sap/hana-client',
27
+ 'better-sqlite3',
28
+ 'mongodb',
29
+ 'oracledb',
30
+ 'pg-native',
31
+ 'mysql',
32
+ 'ioredis',
33
+ 'hdb-pool',
34
+ 'mysql2',
35
+ 'mssql',
36
+ 'sql.js',
37
+ 'pnpapi',
38
+ 'next',
39
+ ];
package/package.json CHANGED
@@ -1,43 +1,42 @@
1
1
  {
2
2
  "name": "@atls/code-service",
3
- "version": "0.0.6",
3
+ "version": "0.0.11",
4
4
  "license": "BSD-3-Clause",
5
5
  "main": "dist/index.js",
6
6
  "files": [
7
- "tsconfig.stub.json",
8
- "dist"
7
+ "dist",
8
+ "tsconfig.stub.json"
9
9
  ],
10
10
  "scripts": {
11
- "build": "builder build library",
12
- "postpack": "rm -rf dist",
13
- "prepack": "yarn run build"
11
+ "build": "yarn library build",
12
+ "prepack": "yarn run build",
13
+ "postpack": "rm -rf dist"
14
+ },
15
+ "dependencies": {
16
+ "@atls/config-typescript": "0.0.1",
17
+ "@atls/webpack-proto-imports-loader": "0.0.6",
18
+ "@atls/webpack-start-server-plugin": "0.0.4",
19
+ "@yarnpkg/cli": "^3.2.0-rc.11",
20
+ "@yarnpkg/core": "^3.2.0-rc.11",
21
+ "fast-glob": "^3.2.7",
22
+ "string-replace-loader": "^3.0.3",
23
+ "ts-loader": "^9.2.6",
24
+ "typescript": "^4.5.5",
25
+ "webpack": "^5.67.0",
26
+ "webpack-chain": "^6.5.1"
14
27
  },
15
28
  "devDependencies": {
16
- "@atls/tools-builder": "0.0.0",
17
- "@types/file-loader": "5.0.1",
18
- "@types/jest": "^26.0.24",
19
- "@types/node": "^14.17.0",
29
+ "@types/jest": "^27.4.0",
30
+ "@types/node": "^17.0.10",
20
31
  "@types/protocol-buffers-schema": "3.4.1",
21
32
  "@types/wait-for-localhost": "3.1.0",
22
33
  "@types/webpack": "^5.28.0",
23
- "@yarnpkg/fslib": "^2.5.0-rc.12",
34
+ "@yarnpkg/fslib": "^2.6.1-rc.6",
24
35
  "wait-for-localhost": "^3.3.0"
25
36
  },
26
37
  "publishConfig": {
27
38
  "main": "dist/index.js",
28
39
  "typings": "dist/index.d.ts"
29
40
  },
30
- "dependencies": {
31
- "@atls/code-typescript": "0.0.4",
32
- "@atls/webpack-proto-imports-loader": "0.0.4",
33
- "@yarnpkg/cli": "^3.0.0-rc.12",
34
- "@yarnpkg/core": "^3.0.0-rc.12",
35
- "fast-glob": "^3.2.5",
36
- "string-replace-loader": "^3.0.1",
37
- "ts-loader": "^9.2.3",
38
- "typescript": "^4.3.5",
39
- "webpack": "^5.44.0",
40
- "webpack-chain": "^6.5.1"
41
- },
42
41
  "typings": "dist/index.d.ts"
43
42
  }
package/dist/build.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export interface BuildOptions {
2
- cwd: string;
3
- }
4
- export interface BuildResult {
5
- errors: any[];
6
- warnings: any[];
7
- }
8
- export declare const build: ({ cwd }: BuildOptions, plugins?: any) => Promise<BuildResult>;
package/dist/build.js DELETED
@@ -1,41 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.build = void 0;
7
- const webpack_1 = __importDefault(require("webpack"));
8
- const webpack_2 = require("./webpack");
9
- const build = async ({ cwd }, plugins) => {
10
- const config = await webpack_2.createWebpackConfig(cwd, 'production', plugins);
11
- const compiler = webpack_1.default(config);
12
- return new Promise((resolve, reject) => {
13
- compiler.run((error, stats) => {
14
- if (error) {
15
- if (!error.message) {
16
- reject(error);
17
- }
18
- else {
19
- resolve({
20
- errors: [{ message: error.message }],
21
- warnings: [],
22
- });
23
- }
24
- }
25
- else if (stats) {
26
- const { errors = [], warnings = [] } = stats.toJson();
27
- resolve({
28
- errors: errors.map((error) => ({ message: error.message })),
29
- warnings: warnings.map((warning) => ({ message: warning.message })),
30
- });
31
- }
32
- else {
33
- resolve({
34
- errors: [],
35
- warnings: [],
36
- });
37
- }
38
- });
39
- });
40
- };
41
- exports.build = build;
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './build';
2
- export * from './watch';
package/dist/watch.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { WebpackConfigPlugin } from './webpack';
2
- export interface WatchOptions {
3
- cwd: string;
4
- }
5
- export declare const watch: ({ cwd }: WatchOptions, plugins?: WebpackConfigPlugin[], callback?: (error?: any) => undefined) => Promise<any>;
package/dist/watch.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.watch = void 0;
7
- const webpack_1 = __importDefault(require("webpack"));
8
- const webpack_2 = require("./webpack");
9
- const watch = async ({ cwd }, plugins = [], callback = (error) => undefined) => {
10
- const config = await webpack_2.createWebpackConfig(cwd, 'development', plugins);
11
- const compiler = webpack_1.default(config);
12
- return compiler.watch({}, callback);
13
- };
14
- exports.watch = watch;
@@ -1,3 +0,0 @@
1
- export declare const unusedExternals: string[];
2
- export declare const getUnpluggedDependencies: () => Promise<Set<string>>;
3
- export declare const getExternals: (cwd: string) => Promise<Array<string>>;
@@ -1 +0,0 @@
1
- export * from './webpack.config';
@@ -1 +0,0 @@
1
- export declare const getResolveAliases: (cwd: string) => Promise<any>;
@@ -1,6 +0,0 @@
1
- export interface WebpackConfigPlugin {
2
- name: string;
3
- use: any;
4
- args: any[];
5
- }
6
- export declare const createWebpackConfig: (cwd: any, environment: any, plugins?: WebpackConfigPlugin[]) => Promise<any>;
@@ -1 +0,0 @@
1
- {}