@intlayer/webpack 1.0.0 → 1.2.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/dist/cjs/getEntries.cjs +41 -0
- package/dist/cjs/getEntries.cjs.map +1 -0
- package/dist/cjs/getEntries.d.ts +5 -0
- package/dist/cjs/index.cjs +12 -24
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/utils.cjs +32 -31
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.ts +7 -0
- package/dist/cjs/webpack-plugin.cjs +12 -161
- package/dist/cjs/webpack-plugin.cjs.map +1 -1
- package/dist/cjs/webpack-plugin.d.ts +5 -0
- package/dist/cjs/webpack.config.cjs +53 -63
- package/dist/cjs/webpack.config.cjs.map +1 -1
- package/dist/cjs/webpack.config.d.ts +7 -0
- package/dist/esm/getEntries.d.mts +5 -0
- package/dist/esm/getEntries.mjs +17 -0
- package/dist/esm/getEntries.mjs.map +1 -0
- package/dist/esm/index.d.mts +4 -9
- package/dist/esm/index.mjs +4 -8
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/utils.d.mts +5 -2
- package/dist/esm/utils.mjs +15 -17
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/esm/webpack-plugin.d.mts +1 -11
- package/dist/esm/webpack-plugin.mjs +8 -142
- package/dist/esm/webpack-plugin.mjs.map +1 -1
- package/dist/esm/webpack.config.d.mts +2 -2
- package/dist/esm/webpack.config.mjs +48 -39
- package/dist/esm/webpack.config.mjs.map +1 -1
- package/package.json +14 -18
- package/src/getEntries.ts +19 -0
- package/src/index.ts +2 -12
- package/src/utils.ts +19 -19
- package/src/webpack-plugin.ts +5 -180
- package/src/webpack.config.ts +32 -28
- package/dist/cjs/scripts/bundle.cjs +0 -68
- package/dist/cjs/scripts/bundle.cjs.map +0 -1
- package/dist/cjs/scripts/index.cjs +0 -33
- package/dist/cjs/scripts/index.cjs.map +0 -1
- package/dist/cjs/scripts/startServer.cjs +0 -44
- package/dist/cjs/scripts/startServer.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +0 -92
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs +0 -35
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +0 -83
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +0 -122
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs +0 -41
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +0 -50
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +0 -47
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +0 -70
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs +0 -112
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs.map +0 -1
- package/dist/esm/scripts/bundle.d.mts +0 -7
- package/dist/esm/scripts/bundle.mjs +0 -35
- package/dist/esm/scripts/bundle.mjs.map +0 -1
- package/dist/esm/scripts/index.d.mts +0 -3
- package/dist/esm/scripts/index.mjs +0 -3
- package/dist/esm/scripts/index.mjs.map +0 -1
- package/dist/esm/scripts/startServer.d.mts +0 -5
- package/dist/esm/scripts/startServer.mjs +0 -10
- package/dist/esm/scripts/startServer.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +0 -6
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +0 -52
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_main/index.d.mts +0 -1
- package/dist/esm/transpiler/dictionary_to_main/index.mjs +0 -2
- package/dist/esm/transpiler/dictionary_to_main/index.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +0 -7
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +0 -43
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +0 -42
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +0 -84
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/index.d.mts +0 -10
- package/dist/esm/transpiler/dictionary_to_type/index.mjs +0 -3
- package/dist/esm/transpiler/dictionary_to_type/index.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.mts +0 -44
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs +0 -19
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +0 -4
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +0 -4
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.d.mts +0 -10
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +0 -39
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.mts +0 -8
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs +0 -70
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs.map +0 -1
- package/src/scripts/bundle.ts +0 -44
- package/src/scripts/index.ts +0 -2
- package/src/scripts/startServer.ts +0 -14
- package/src/transpiler/dictionary_to_main/createDictionaryList.ts +0 -65
- package/src/transpiler/dictionary_to_main/index.ts +0 -1
- package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +0 -70
- package/src/transpiler/dictionary_to_type/createType.ts +0 -140
- package/src/transpiler/dictionary_to_type/index.ts +0 -2
- package/src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts +0 -60
- package/src/transpiler/intlater_module_to_dictionary/index.ts +0 -3
- package/src/transpiler/intlater_module_to_dictionary/processModule.ts +0 -69
- package/src/transpiler/intlater_module_to_dictionary/transpileBundledCode.ts +0 -107
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/webpack",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "Webpack application for IntLayer -
|
|
5
|
+
"description": "Webpack application for IntLayer - Transpile Intlayer declaration files into dictionaries using webpack.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"intlayer",
|
|
8
8
|
"webpack",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"homepage": "https://github.com/aypineau/intlayer",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "https://github.com/aypineau/intlayer"
|
|
19
|
+
"url": "git+https://github.com/aypineau/intlayer.git"
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": {
|
|
@@ -46,35 +46,31 @@
|
|
|
46
46
|
"./package.json"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
+
"chokidar": "^3.6.0",
|
|
49
50
|
"crypto-js": "^4.2.0",
|
|
50
51
|
"esbuild": "^0.20.2",
|
|
51
52
|
"esbuild-loader": "^4.1.0",
|
|
52
|
-
"glob": "^10.3.
|
|
53
|
+
"glob": "^10.3.12",
|
|
53
54
|
"node-loader": "^2.0.0",
|
|
54
55
|
"rimraf": "5.0.5",
|
|
55
56
|
"util": "^0.12.5",
|
|
56
57
|
"webpack": "^5.91.0",
|
|
57
58
|
"webpack-cli": "^5.1.4",
|
|
58
59
|
"webpack-dev-server": "^5.0.4",
|
|
59
|
-
"
|
|
60
|
-
"@intlayer/cli": "^1.
|
|
61
|
-
"@intlayer/config": "^1.
|
|
62
|
-
"@intlayer/core": "^1.
|
|
60
|
+
"@intlayer/chokidar": "^1.2.0",
|
|
61
|
+
"@intlayer/cli": "^1.2.0",
|
|
62
|
+
"@intlayer/config": "^1.2.0",
|
|
63
|
+
"@intlayer/core": "^1.2.0",
|
|
64
|
+
"intlayer": "^1.2.0"
|
|
63
65
|
},
|
|
64
66
|
"devDependencies": {
|
|
65
|
-
"@changesets/changelog-github": "0.5.0",
|
|
66
67
|
"@changesets/cli": "2.27.1",
|
|
67
68
|
"@types/crypto-js": "^4.2.2",
|
|
68
|
-
"@types/node": "^20.
|
|
69
|
-
"@types/uuid": "^9.0.8",
|
|
70
|
-
"@types/webpack-watch-files-plugin": "^1.1.3",
|
|
71
|
-
"@types/yargs": "^17.0.32",
|
|
72
|
-
"node-polyfill-webpack-plugin": "^3.0.0",
|
|
69
|
+
"@types/node": "^20.12.7",
|
|
73
70
|
"tsup": "^8.0.2",
|
|
74
|
-
"typescript": "^5.
|
|
75
|
-
"
|
|
76
|
-
"@utils/
|
|
77
|
-
"@utils/ts-config": "^1.0.0"
|
|
71
|
+
"typescript": "^5.4.5",
|
|
72
|
+
"@utils/eslint-config": "^1.0.1",
|
|
73
|
+
"@utils/ts-config": "^1.0.1"
|
|
78
74
|
},
|
|
79
75
|
"engines": {
|
|
80
76
|
"node": ">=14.18"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getConfiguration } from '@intlayer/config';
|
|
2
|
+
import { sync } from 'glob';
|
|
3
|
+
import type { EntryObject } from 'webpack';
|
|
4
|
+
import { getFileHash } from './utils';
|
|
5
|
+
|
|
6
|
+
const { content } = getConfiguration();
|
|
7
|
+
const { watchedFilesPatternWithPath } = content;
|
|
8
|
+
|
|
9
|
+
export const getEntries = (): EntryObject =>
|
|
10
|
+
sync(watchedFilesPatternWithPath).reduce((obj, el) => {
|
|
11
|
+
const hash = getFileHash(el);
|
|
12
|
+
|
|
13
|
+
obj[`intlayer-content/${hash}`] = {
|
|
14
|
+
import: el,
|
|
15
|
+
dependOn: undefined,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return obj;
|
|
19
|
+
}, {} as EntryObject);
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { devServerConfig, webpackConfig } from './webpack.config';
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
bundle,
|
|
7
|
-
watch,
|
|
8
|
-
startServer,
|
|
9
|
-
devServerConfig,
|
|
10
|
-
webpackConfig,
|
|
11
|
-
IntLayerPlugin,
|
|
12
|
-
};
|
|
1
|
+
export { IntLayerPlugin } from './webpack-plugin';
|
|
2
|
+
export { devServerConfig, webpackConfig } from './webpack.config';
|
package/src/utils.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import crypto from 'crypto-js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Set the __dirname global variable to make the config work in both ESM and CJS environments
|
|
7
|
+
*/
|
|
8
|
+
export const defineDirname = () => {
|
|
9
|
+
const isESModule = typeof import.meta.url === 'string';
|
|
10
|
+
|
|
11
|
+
const filename = isESModule
|
|
12
|
+
? fileURLToPath(import.meta.url)
|
|
13
|
+
: require('url').pathToFileURL(__filename).toString();
|
|
14
|
+
|
|
15
|
+
globalThis.__filename = globalThis.__filename ?? filename;
|
|
16
|
+
globalThis.__dirname = globalThis.__dirname ?? path.dirname(__filename);
|
|
17
|
+
};
|
|
2
18
|
|
|
3
19
|
export const getFileHash = (filePath: string) => {
|
|
4
|
-
const hash = SHA3(filePath);
|
|
20
|
+
const hash = crypto.SHA3(filePath);
|
|
5
21
|
|
|
6
22
|
return hash
|
|
7
|
-
.toString(enc.Base64)
|
|
23
|
+
.toString(crypto.enc.Base64)
|
|
8
24
|
.replace(/[^A-Z\d]/gi, '')
|
|
9
25
|
.substring(0, 20);
|
|
10
26
|
};
|
|
11
|
-
|
|
12
|
-
export const transformToCamelCase = (string: string): string => {
|
|
13
|
-
// Split the string into words using a regex that finds spaces, hyphens, and underscores
|
|
14
|
-
const words = string.split(/[\s\-_]+/);
|
|
15
|
-
|
|
16
|
-
// Transform each word except the first to have its first letter uppercase
|
|
17
|
-
const camelCasedWords = words.map((word, index) => {
|
|
18
|
-
if (index === 0) {
|
|
19
|
-
return word[0].toUpperCase() + word.slice(1);
|
|
20
|
-
}
|
|
21
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Join the words back together
|
|
25
|
-
return camelCasedWords.join('');
|
|
26
|
-
};
|
package/src/webpack-plugin.ts
CHANGED
|
@@ -1,185 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getConfiguration } from '@intlayer/config';
|
|
3
|
-
import { sync } from 'glob';
|
|
4
|
-
import { DynamicEntryPlugin, type Compiler } from 'webpack';
|
|
5
|
-
import { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList';
|
|
6
|
-
import { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';
|
|
7
|
-
import { createTypes } from './transpiler/dictionary_to_type/createType';
|
|
8
|
-
import { transpileBundledCode } from './transpiler/intlater_module_to_dictionary/transpileBundledCode';
|
|
9
|
-
import { getFileHash } from './utils';
|
|
1
|
+
import { watch } from '@intlayer/chokidar';
|
|
10
2
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const getBundledFilePathFromIntlayerModule = (filePath: string): string => {
|
|
14
|
-
const hash = getFileHash(filePath);
|
|
15
|
-
|
|
16
|
-
return `${bundleDir}/${hash}${bundleFileExtension}`;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const { content } = getConfiguration();
|
|
20
|
-
const { bundleDir, baseDir, bundleFileExtension, watchedFilesPatternWithPath } =
|
|
21
|
-
content;
|
|
3
|
+
// Watch mode or on time build
|
|
4
|
+
const persistent = process.env.NODE_ENV === 'development';
|
|
22
5
|
|
|
23
6
|
export class IntLayerPlugin {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
private addedFiles: Set<string>;
|
|
27
|
-
|
|
28
|
-
constructor() {
|
|
29
|
-
this.managedFiles = new Set();
|
|
30
|
-
this.updatedFiles = new Set();
|
|
31
|
-
this.addedFiles = new Set();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// function to initialize the dictionaries
|
|
35
|
-
public async initDictionaries() {
|
|
36
|
-
const outputFiles = [...this.managedFiles].map((file) =>
|
|
37
|
-
resolve(bundleDir, file)
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const dictionaries = (await transpileBundledCode(outputFiles)) ?? [];
|
|
41
|
-
|
|
42
|
-
console.info(
|
|
43
|
-
`Dictionaries: \n ${dictionaries.map(getRelativePath).join('\n')}`
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
console.info('Building TypeScript types...');
|
|
47
|
-
createTypes(dictionaries);
|
|
48
|
-
|
|
49
|
-
console.info('Building type index...');
|
|
50
|
-
createModuleAugmentation();
|
|
51
|
-
|
|
52
|
-
console.info('Building main...');
|
|
53
|
-
createDictionaryList();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// function to process when intlayer module files content are changed
|
|
57
|
-
public async processFilesChanges() {
|
|
58
|
-
const dictionaries =
|
|
59
|
-
(await transpileBundledCode([...this.updatedFiles])) ?? [];
|
|
60
|
-
|
|
61
|
-
console.info(
|
|
62
|
-
`Updated dictionaries: \n ${dictionaries.map(getRelativePath).join('\n')}`
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
console.info('Updating TypeScript types...');
|
|
66
|
-
createTypes(dictionaries);
|
|
67
|
-
|
|
68
|
-
this.updatedFiles.clear();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// function to process when new intlayer module is detected
|
|
72
|
-
public async processNewFiles() {
|
|
73
|
-
const dictionaries =
|
|
74
|
-
(await transpileBundledCode([...this.addedFiles])) ?? [];
|
|
75
|
-
|
|
76
|
-
console.info(
|
|
77
|
-
`New dictionaries: \n ${dictionaries.map(getRelativePath).join('\n')}`
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
console.info('Building TypeScript types...');
|
|
81
|
-
createTypes(dictionaries);
|
|
82
|
-
|
|
83
|
-
console.info('Building type index...');
|
|
84
|
-
createModuleAugmentation();
|
|
85
|
-
|
|
86
|
-
console.info('Building main...');
|
|
87
|
-
createDictionaryList();
|
|
88
|
-
|
|
89
|
-
this.managedFiles = new Set([...this.managedFiles, ...this.addedFiles]);
|
|
90
|
-
this.addedFiles.clear();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public async detectFileAddedOrRemoved() {
|
|
94
|
-
const filesFound: string[] = [];
|
|
95
|
-
|
|
96
|
-
for (const pattern of watchedFilesPatternWithPath) {
|
|
97
|
-
sync(pattern).map((file) => filesFound.push(file));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Detect new files by comparing with files emitted in previous compilation
|
|
101
|
-
const newFiles = new Set(
|
|
102
|
-
filesFound.filter((x) => !this.managedFiles.has(x))
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const removedFiles = new Set(
|
|
106
|
-
[...this.managedFiles].filter((x) => !filesFound.includes(x))
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
// Check if there is new files
|
|
111
|
-
newFiles.size > 0
|
|
112
|
-
) {
|
|
113
|
-
console.info('New files:', [...newFiles]);
|
|
114
|
-
|
|
115
|
-
this.addedFiles = newFiles;
|
|
116
|
-
|
|
117
|
-
await this.processNewFiles();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
// Check if there is removed files
|
|
122
|
-
removedFiles.size > 0
|
|
123
|
-
) {
|
|
124
|
-
console.info('Removed files:', [...removedFiles]);
|
|
125
|
-
|
|
126
|
-
this.managedFiles = new Set(
|
|
127
|
-
[...this.managedFiles].filter((x) => !removedFiles.has(x))
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// After the compilation, transpile the changed files if any
|
|
132
|
-
if (this.updatedFiles.size > 0) {
|
|
133
|
-
await this.processFilesChanges();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
apply(compiler: Compiler): void {
|
|
138
|
-
compiler.hooks.entryOption.tap('EntryOptionPlugin', (context, entry) => {
|
|
139
|
-
if (typeof entry === 'function') {
|
|
140
|
-
// DynamicEntryPlugin is used to add entries at runtime when files are created, updated or deleted
|
|
141
|
-
new DynamicEntryPlugin(context, entry).apply(compiler);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return true;
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
compiler.hooks.afterEmit.tapAsync(
|
|
148
|
-
'IntLayerPlugin - Process dictionaries',
|
|
149
|
-
async (compilation, callback) => {
|
|
150
|
-
// Get a set of files that will be emitted in this compilation
|
|
151
|
-
const currentEmitFiles = new Set(Object.keys(compilation.assets));
|
|
152
|
-
|
|
153
|
-
if (
|
|
154
|
-
// Check if this first load
|
|
155
|
-
!this.managedFiles.size
|
|
156
|
-
) {
|
|
157
|
-
// Update previousEmitFiles for the next compilation
|
|
158
|
-
this.managedFiles = currentEmitFiles;
|
|
159
|
-
|
|
160
|
-
await this.initDictionaries();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
await this.detectFileAddedOrRemoved();
|
|
164
|
-
|
|
165
|
-
callback();
|
|
166
|
-
}
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
// Detect modified files on watch mode
|
|
170
|
-
compiler.hooks.watchRun.tap(
|
|
171
|
-
'IntLayerPlugin - Change detection',
|
|
172
|
-
(compilation) => {
|
|
173
|
-
if (compilation.modifiedFiles) {
|
|
174
|
-
const updatedFiles = Array.from(compilation.modifiedFiles);
|
|
175
|
-
|
|
176
|
-
const outputFileNames = updatedFiles.map(
|
|
177
|
-
getBundledFilePathFromIntlayerModule
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
this.updatedFiles = new Set(outputFileNames);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
);
|
|
7
|
+
apply(): void {
|
|
8
|
+
watch({ persistent });
|
|
184
9
|
}
|
|
185
10
|
}
|
package/src/webpack.config.ts
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { getConfiguration } from '@intlayer/config';
|
|
3
|
-
import { sync } from 'glob';
|
|
4
3
|
import type { Configuration as WebPackConfiguration } from 'webpack';
|
|
5
4
|
import type { Configuration as DevServerConfiguration } from 'webpack-dev-server';
|
|
6
|
-
import {
|
|
5
|
+
import { getEntries } from './getEntries';
|
|
6
|
+
import { defineDirname } from './utils';
|
|
7
7
|
import { IntLayerPlugin } from './webpack-plugin';
|
|
8
8
|
|
|
9
9
|
const { content } = getConfiguration({
|
|
10
|
-
verbose:
|
|
10
|
+
verbose: false,
|
|
11
11
|
});
|
|
12
|
-
const {
|
|
12
|
+
const { fileExtensions } = content;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
obj[hash] = el;
|
|
20
|
-
return obj;
|
|
21
|
-
},
|
|
22
|
-
{} as Record<string, string>
|
|
23
|
-
);
|
|
14
|
+
/**
|
|
15
|
+
* Set the __dirname global variable to make the config work in both ESM and CJS environments
|
|
16
|
+
*/
|
|
17
|
+
defineDirname();
|
|
24
18
|
|
|
25
19
|
// For web interface
|
|
26
20
|
export const devServerConfig: DevServerConfiguration = {
|
|
@@ -48,9 +42,7 @@ export const devServerConfig: DevServerConfiguration = {
|
|
|
48
42
|
},
|
|
49
43
|
|
|
50
44
|
// Content base
|
|
51
|
-
static: {
|
|
52
|
-
directory: bundleDir,
|
|
53
|
-
},
|
|
45
|
+
static: {},
|
|
54
46
|
};
|
|
55
47
|
|
|
56
48
|
export const webpackConfig: WebPackConfiguration = {
|
|
@@ -59,18 +51,17 @@ export const webpackConfig: WebPackConfiguration = {
|
|
|
59
51
|
// Entry point of the application
|
|
60
52
|
target: 'node', // Specifies the target environment
|
|
61
53
|
|
|
62
|
-
entry:
|
|
54
|
+
entry: getEntries,
|
|
63
55
|
output: {
|
|
64
56
|
clean: true, // Clean the output directory before emit
|
|
65
57
|
library: 'IntlLayerContent',
|
|
66
58
|
libraryTarget: 'umd',
|
|
67
|
-
filename: `[name]
|
|
68
|
-
path: bundleDir,
|
|
59
|
+
filename: `[name].bundle.js`,
|
|
69
60
|
},
|
|
70
61
|
|
|
71
62
|
cache: false,
|
|
72
63
|
|
|
73
|
-
|
|
64
|
+
devtool: 'source-map',
|
|
74
65
|
|
|
75
66
|
// stats: {
|
|
76
67
|
// preset: 'errors-only',
|
|
@@ -82,7 +73,7 @@ export const webpackConfig: WebPackConfiguration = {
|
|
|
82
73
|
extensions: ['.ts', '.js', '.json', '.wasm', '.ts', '.tsx', '.mjs', '.cjs'],
|
|
83
74
|
modules: [
|
|
84
75
|
// To find the loader module
|
|
85
|
-
join(__dirname, '..', 'node_modules'), // In the project node_modules
|
|
76
|
+
join(globalThis.__dirname, '..', 'node_modules'), // In the project node_modules
|
|
86
77
|
join(process.cwd(), 'node_modules'), // In the project node_modules
|
|
87
78
|
join(process.cwd(), 'node_modules', 'intlayer-cli', 'node_modules'), // Or via another project by importing intlayer
|
|
88
79
|
join(
|
|
@@ -111,15 +102,28 @@ export const webpackConfig: WebPackConfiguration = {
|
|
|
111
102
|
'node_modules'
|
|
112
103
|
), // Or via another project by importing intlayer
|
|
113
104
|
],
|
|
114
|
-
// roots: [
|
|
115
|
-
// join(process.cwd()), // Project context
|
|
116
|
-
// join(process.cwd(), '@intlayer/webpack'), // Or via CLI in another project
|
|
117
|
-
// join(process.cwd(), 'intlayer', '@intlayer/webpack'), // Or via CLI in another project
|
|
118
|
-
// ],
|
|
119
105
|
},
|
|
120
106
|
|
|
121
107
|
module: {
|
|
122
108
|
rules: [
|
|
109
|
+
{
|
|
110
|
+
// Rule for .content.ts files
|
|
111
|
+
test: new RegExp(`(${fileExtensions.join('|')})$`),
|
|
112
|
+
use: [
|
|
113
|
+
{
|
|
114
|
+
// Transpile with esbuild-loader
|
|
115
|
+
loader: 'esbuild-loader',
|
|
116
|
+
options: {
|
|
117
|
+
// JavaScript version to compile to
|
|
118
|
+
target: 'es2015',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
// {
|
|
122
|
+
// // Custom loader to process the transpiled code
|
|
123
|
+
// loader: resolve('./intlayer-loader'),
|
|
124
|
+
// },
|
|
125
|
+
],
|
|
126
|
+
},
|
|
123
127
|
{
|
|
124
128
|
test: /\.node$/,
|
|
125
129
|
loader: 'node-loader',
|
|
@@ -127,7 +131,7 @@ export const webpackConfig: WebPackConfiguration = {
|
|
|
127
131
|
// Use esbuild to compile JavaScript & TypeScript
|
|
128
132
|
{
|
|
129
133
|
// Match `.js`, `.jsx`, `.ts` or `.tsx` files
|
|
130
|
-
test: /\.
|
|
134
|
+
test: /\.(jsx|js|ts|tsx|mjs|cjs)?$/,
|
|
131
135
|
loader: 'esbuild-loader',
|
|
132
136
|
options: {
|
|
133
137
|
// JavaScript version to compile to
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: () => from[key],
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var bundle_exports = {};
|
|
24
|
-
__export(bundle_exports, {
|
|
25
|
-
bundle: () => bundle,
|
|
26
|
-
watch: () => watch,
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(bundle_exports);
|
|
29
|
-
const bundle = (compiler) =>
|
|
30
|
-
// Run the compiler
|
|
31
|
-
compiler.run((err, stats) => {
|
|
32
|
-
if (err) {
|
|
33
|
-
console.error("Webpack compilation error:", err);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
console.info("Webpack compilation successful.");
|
|
37
|
-
if (stats)
|
|
38
|
-
console.info(
|
|
39
|
-
stats.toString({
|
|
40
|
-
// Add options here to customize the stats output
|
|
41
|
-
colors: true,
|
|
42
|
-
})
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
const watch = (compiler) =>
|
|
46
|
-
// Run the compiler
|
|
47
|
-
compiler.watch({}, (err, stats) => {
|
|
48
|
-
if (err) {
|
|
49
|
-
console.error("Webpack compilation error:", err);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
console.info("Webpack compilation successful.");
|
|
53
|
-
if (stats)
|
|
54
|
-
console.info(
|
|
55
|
-
stats.toString({
|
|
56
|
-
// Add options here to customize the stats output
|
|
57
|
-
colors: true,
|
|
58
|
-
})
|
|
59
|
-
);
|
|
60
|
-
console.info("Watch IntLayer content...");
|
|
61
|
-
});
|
|
62
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
-
0 &&
|
|
64
|
-
(module.exports = {
|
|
65
|
-
bundle,
|
|
66
|
-
watch,
|
|
67
|
-
});
|
|
68
|
-
//# sourceMappingURL=bundle.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/scripts/bundle.ts"],"sourcesContent":["import type { Compiler } from 'webpack';\n\nexport const bundle = (compiler: Compiler) =>\n // Run the compiler\n compiler.run((err, stats) => {\n // Handle errors and webpack compilation stats\n if (err) {\n console.error('Webpack compilation error:', err);\n return;\n }\n\n console.info('Webpack compilation successful.');\n\n if (stats)\n console.info(\n stats.toString({\n // Add options here to customize the stats output\n colors: true,\n })\n );\n });\n\nexport const watch = (compiler: Compiler) =>\n // Run the compiler\n compiler.watch({}, (err, stats) => {\n // Handle errors and webpack compilation stats\n if (err) {\n console.error('Webpack compilation error:', err);\n return;\n }\n\n console.info('Webpack compilation successful.');\n\n if (stats)\n console.info(\n stats.toString({\n // Add options here to customize the stats output\n colors: true,\n })\n );\n\n // After successful compilation, start the server\n console.info('Watch IntLayer content...');\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,SAAS,CAAC;AAAA;AAAA,EAErB,SAAS,IAAI,CAAC,KAAK,UAAU;AAE3B,QAAI,KAAK;AACP,cAAQ,MAAM,8BAA8B,GAAG;AAC/C;AAAA,IACF;AAEA,YAAQ,KAAK,iCAAiC;AAE9C,QAAI;AACF,cAAQ;AAAA,QACN,MAAM,SAAS;AAAA;AAAA,UAEb,QAAQ;AAAA,QACV,CAAC;AAAA,MACH;AAAA,EACJ,CAAC;AAAA;AAEI,MAAM,QAAQ,CAAC;AAAA;AAAA,EAEpB,SAAS,MAAM,CAAC,GAAG,CAAC,KAAK,UAAU;AAEjC,QAAI,KAAK;AACP,cAAQ,MAAM,8BAA8B,GAAG;AAC/C;AAAA,IACF;AAEA,YAAQ,KAAK,iCAAiC;AAE9C,QAAI;AACF,cAAQ;AAAA,QACN,MAAM,SAAS;AAAA;AAAA,UAEb,QAAQ;AAAA,QACV,CAAC;AAAA,MACH;AAGF,YAAQ,KAAK,2BAA2B;AAAA,EAC1C,CAAC;AAAA;","names":[]}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if ((from && typeof from === "object") || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, {
|
|
11
|
-
get: () => from[key],
|
|
12
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (
|
|
18
|
-
__copyProps(target, mod, "default"),
|
|
19
|
-
secondTarget && __copyProps(secondTarget, mod, "default")
|
|
20
|
-
);
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var scripts_exports = {};
|
|
24
|
-
module.exports = __toCommonJS(scripts_exports);
|
|
25
|
-
__reExport(scripts_exports, require("./startServer.cjs"), module.exports);
|
|
26
|
-
__reExport(scripts_exports, require("./bundle.cjs"), module.exports);
|
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
-
0 &&
|
|
29
|
-
(module.exports = {
|
|
30
|
-
...require("./startServer.cjs"),
|
|
31
|
-
...require("./bundle.cjs"),
|
|
32
|
-
});
|
|
33
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/scripts/index.ts"],"sourcesContent":["export * from './startServer';\nexport * from './bundle';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,4BAAc,0BAAd;AACA,4BAAc,qBADd;","names":[]}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: () => from[key],
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var startServer_exports = {};
|
|
24
|
-
__export(startServer_exports, {
|
|
25
|
-
startServer: () => startServer,
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(startServer_exports);
|
|
28
|
-
var import_webpack = require("../webpack.config.cjs");
|
|
29
|
-
const WebpackDevServer = require("webpack-dev-server");
|
|
30
|
-
const startServer = (compiler) => {
|
|
31
|
-
const devServer = new WebpackDevServer(
|
|
32
|
-
import_webpack.devServerConfig,
|
|
33
|
-
compiler
|
|
34
|
-
);
|
|
35
|
-
devServer.startCallback(() => {
|
|
36
|
-
console.info("Webpack Dev Server is running...");
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
-
0 &&
|
|
41
|
-
(module.exports = {
|
|
42
|
-
startServer,
|
|
43
|
-
});
|
|
44
|
-
//# sourceMappingURL=startServer.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/scripts/startServer.ts"],"sourcesContent":["import type { Compiler } from 'webpack';\nimport { devServerConfig } from '../webpack.config';\n\nconst WebpackDevServer = require('webpack-dev-server');\n\nexport const startServer = (compiler: Compiler) => {\n // Create a new instance of webpack-dev-server\n const devServer = new WebpackDevServer(devServerConfig, compiler);\n\n // Start the server\n devServer.startCallback(() => {\n console.info('Webpack Dev Server is running...');\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAgC;AAEhC,MAAM,mBAAmB,QAAQ,oBAAoB;AAE9C,MAAM,cAAc,CAAC,aAAuB;AAEjD,QAAM,YAAY,IAAI,iBAAiB,gCAAiB,QAAQ;AAGhE,YAAU,cAAc,MAAM;AAC5B,YAAQ,KAAK,kCAAkC;AAAA,EACjD,CAAC;AACH;","names":[]}
|