@vocab/webpack 1.1.6 → 1.2.1
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/declarations/src/index.d.ts +2 -1
- package/dist/declarations/src/loader.d.ts +2 -2
- package/dist/declarations/src/web.d.ts +1 -1
- package/dist/vocab-webpack.cjs.dev.js +3 -1
- package/dist/vocab-webpack.cjs.prod.js +3 -1
- package/dist/vocab-webpack.esm.js +3 -2
- package/loader/dist/vocab-webpack-loader.cjs.dev.js +61 -8
- package/loader/dist/vocab-webpack-loader.cjs.prod.js +61 -8
- package/loader/dist/vocab-webpack-loader.esm.js +41 -8
- package/package.json +4 -3
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { UserConfig } from '@vocab/
|
|
1
|
+
import type { UserConfig } from '@vocab/core';
|
|
2
2
|
import type { Compiler } from 'webpack';
|
|
3
3
|
interface UserOptions extends Partial<UserConfig> {
|
|
4
4
|
configFile?: string;
|
|
5
5
|
}
|
|
6
|
+
export declare const compiledVocabFileFilter: RegExp;
|
|
6
7
|
export declare class VocabWebpackPlugin {
|
|
7
8
|
options: UserConfig;
|
|
8
9
|
constructor({ configFile, ...rest }?: UserOptions);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UserConfig } from '@vocab/
|
|
1
|
+
import type { UserConfig } from '@vocab/core';
|
|
2
2
|
import type { LoaderContext as WebpackLoaderContext } from 'webpack';
|
|
3
3
|
type LoaderContext = WebpackLoaderContext<UserConfig>;
|
|
4
|
-
export default function vocabLoader(this: LoaderContext): Promise<void>;
|
|
4
|
+
export default function vocabLoader(this: LoaderContext, source: string): Promise<void>;
|
|
5
5
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { TranslationModule } from '@vocab/
|
|
1
|
+
import type { TranslationModule } from '@vocab/core';
|
|
2
2
|
export { createTranslationFile } from '@vocab/core/translation-file';
|
|
3
3
|
export declare const createLanguage: (moduleId: string, loadImport: () => Promise<any>) => TranslationModule<any>;
|
|
@@ -7,6 +7,7 @@ var logger = require('./logger-65149486.cjs.dev.js');
|
|
|
7
7
|
require('chalk');
|
|
8
8
|
require('debug');
|
|
9
9
|
|
|
10
|
+
const compiledVocabFileFilter = /\.vocab[\\/]index\.(?:ts|js|cjs|mjs)$/;
|
|
10
11
|
class VocabWebpackPlugin {
|
|
11
12
|
constructor({
|
|
12
13
|
configFile,
|
|
@@ -31,7 +32,7 @@ class VocabWebpackPlugin {
|
|
|
31
32
|
compiler.options.module.rules = [];
|
|
32
33
|
}
|
|
33
34
|
compiler.options.module.rules.splice(0, 0, {
|
|
34
|
-
test:
|
|
35
|
+
test: compiledVocabFileFilter,
|
|
35
36
|
loader: require.resolve('@vocab/webpack/loader'),
|
|
36
37
|
options: this.options
|
|
37
38
|
});
|
|
@@ -39,3 +40,4 @@ class VocabWebpackPlugin {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
exports.VocabWebpackPlugin = VocabWebpackPlugin;
|
|
43
|
+
exports.compiledVocabFileFilter = compiledVocabFileFilter;
|
|
@@ -7,6 +7,7 @@ var logger = require('./logger-f79e34a8.cjs.prod.js');
|
|
|
7
7
|
require('chalk');
|
|
8
8
|
require('debug');
|
|
9
9
|
|
|
10
|
+
const compiledVocabFileFilter = /\.vocab[\\/]index\.(?:ts|js|cjs|mjs)$/;
|
|
10
11
|
class VocabWebpackPlugin {
|
|
11
12
|
constructor({
|
|
12
13
|
configFile,
|
|
@@ -31,7 +32,7 @@ class VocabWebpackPlugin {
|
|
|
31
32
|
compiler.options.module.rules = [];
|
|
32
33
|
}
|
|
33
34
|
compiler.options.module.rules.splice(0, 0, {
|
|
34
|
-
test:
|
|
35
|
+
test: compiledVocabFileFilter,
|
|
35
36
|
loader: require.resolve('@vocab/webpack/loader'),
|
|
36
37
|
options: this.options
|
|
37
38
|
});
|
|
@@ -39,3 +40,4 @@ class VocabWebpackPlugin {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
exports.VocabWebpackPlugin = VocabWebpackPlugin;
|
|
43
|
+
exports.compiledVocabFileFilter = compiledVocabFileFilter;
|
|
@@ -3,6 +3,7 @@ import { t as trace } from './logger-e1862ea1.esm.js';
|
|
|
3
3
|
import 'chalk';
|
|
4
4
|
import 'debug';
|
|
5
5
|
|
|
6
|
+
const compiledVocabFileFilter = /\.vocab[\\/]index\.(?:ts|js|cjs|mjs)$/;
|
|
6
7
|
class VocabWebpackPlugin {
|
|
7
8
|
constructor({
|
|
8
9
|
configFile,
|
|
@@ -27,11 +28,11 @@ class VocabWebpackPlugin {
|
|
|
27
28
|
compiler.options.module.rules = [];
|
|
28
29
|
}
|
|
29
30
|
compiler.options.module.rules.splice(0, 0, {
|
|
30
|
-
test:
|
|
31
|
+
test: compiledVocabFileFilter,
|
|
31
32
|
loader: require.resolve('@vocab/webpack/loader'),
|
|
32
33
|
options: this.options
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export { VocabWebpackPlugin };
|
|
38
|
+
export { VocabWebpackPlugin, compiledVocabFileFilter };
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var path = require('path');
|
|
6
|
+
var cjsModuleLexer = require('cjs-module-lexer');
|
|
7
|
+
var esModuleLexer = require('es-module-lexer');
|
|
6
8
|
var core = require('@vocab/core');
|
|
7
9
|
var chunkName_dist_vocabWebpackChunkName = require('../../chunk-name/dist/vocab-webpack-chunk-name.cjs.dev.js');
|
|
8
10
|
var logger = require('../../dist/logger-65149486.cjs.dev.js');
|
|
@@ -11,7 +13,27 @@ require('debug');
|
|
|
11
13
|
|
|
12
14
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
13
15
|
|
|
16
|
+
function _interopNamespace(e) {
|
|
17
|
+
if (e && e.__esModule) return e;
|
|
18
|
+
var n = Object.create(null);
|
|
19
|
+
if (e) {
|
|
20
|
+
Object.keys(e).forEach(function (k) {
|
|
21
|
+
if (k !== 'default') {
|
|
22
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return e[k]; }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
n["default"] = e;
|
|
31
|
+
return Object.freeze(n);
|
|
32
|
+
}
|
|
33
|
+
|
|
14
34
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
35
|
+
var cjsModuleLexer__namespace = /*#__PURE__*/_interopNamespace(cjsModuleLexer);
|
|
36
|
+
var esModuleLexer__namespace = /*#__PURE__*/_interopNamespace(esModuleLexer);
|
|
15
37
|
|
|
16
38
|
const trace = logger.trace.extend('loader');
|
|
17
39
|
|
|
@@ -51,7 +73,17 @@ function renderLanguageLoaderAsync(resourcePath, loadedTranslation) {
|
|
|
51
73
|
);
|
|
52
74
|
};
|
|
53
75
|
}
|
|
54
|
-
|
|
76
|
+
function findExportNames(source, mode) {
|
|
77
|
+
if (mode === 'esm') {
|
|
78
|
+
const [, exports] = esModuleLexer__namespace.parse(source);
|
|
79
|
+
return exports;
|
|
80
|
+
}
|
|
81
|
+
const {
|
|
82
|
+
exports
|
|
83
|
+
} = cjsModuleLexer__namespace.parse(source);
|
|
84
|
+
return exports;
|
|
85
|
+
}
|
|
86
|
+
async function vocabLoader(source) {
|
|
55
87
|
trace(`Using vocab loader for ${this.resourcePath}`);
|
|
56
88
|
const callback = this.async();
|
|
57
89
|
if (!callback) {
|
|
@@ -70,14 +102,35 @@ async function vocabLoader() {
|
|
|
70
102
|
return;
|
|
71
103
|
}
|
|
72
104
|
const renderLanguageLoader = renderLanguageLoaderAsync.call(this, devJsonFilePath, loadedTranslation);
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
export default createTranslationFile({
|
|
78
|
-
${loadedLanguages.map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
|
|
79
|
-
});
|
|
105
|
+
const translations = /* ts */`
|
|
106
|
+
const translations = createTranslationFile({
|
|
107
|
+
${Object.keys(loadedTranslation.languages).map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
|
|
108
|
+
});
|
|
80
109
|
`;
|
|
110
|
+
let result;
|
|
111
|
+
|
|
112
|
+
// this is necessary for the Web Assembly boot
|
|
113
|
+
await esModuleLexer__namespace.init;
|
|
114
|
+
const esmExports = findExportNames(source, 'esm');
|
|
115
|
+
if (esmExports.length > 0) {
|
|
116
|
+
const exportName = esmExports[0];
|
|
117
|
+
trace(`Found ESM export '${exportName}' in ${this.resourcePath}`);
|
|
118
|
+
result = /* ts */`
|
|
119
|
+
import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
|
|
120
|
+
${translations}
|
|
121
|
+
export { translations as ${exportName} };
|
|
122
|
+
`;
|
|
123
|
+
} else {
|
|
124
|
+
// init needs to be called and waited upon
|
|
125
|
+
await cjsModuleLexer__namespace.init();
|
|
126
|
+
const exportName = findExportNames(source, 'cjs')[0];
|
|
127
|
+
trace(`Found CJS export '${exportName}' in ${this.resourcePath}`);
|
|
128
|
+
result = /* ts */`
|
|
129
|
+
const { createLanguage, createTranslationFile } = require('@vocab/webpack/${target}');
|
|
130
|
+
${translations}
|
|
131
|
+
exports.${exportName} = translations;
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
81
134
|
trace('Created translation file', result);
|
|
82
135
|
callback(null, result);
|
|
83
136
|
}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var path = require('path');
|
|
6
|
+
var cjsModuleLexer = require('cjs-module-lexer');
|
|
7
|
+
var esModuleLexer = require('es-module-lexer');
|
|
6
8
|
var core = require('@vocab/core');
|
|
7
9
|
var chunkName_dist_vocabWebpackChunkName = require('../../chunk-name/dist/vocab-webpack-chunk-name.cjs.prod.js');
|
|
8
10
|
var logger = require('../../dist/logger-f79e34a8.cjs.prod.js');
|
|
@@ -11,7 +13,27 @@ require('debug');
|
|
|
11
13
|
|
|
12
14
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
13
15
|
|
|
16
|
+
function _interopNamespace(e) {
|
|
17
|
+
if (e && e.__esModule) return e;
|
|
18
|
+
var n = Object.create(null);
|
|
19
|
+
if (e) {
|
|
20
|
+
Object.keys(e).forEach(function (k) {
|
|
21
|
+
if (k !== 'default') {
|
|
22
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return e[k]; }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
n["default"] = e;
|
|
31
|
+
return Object.freeze(n);
|
|
32
|
+
}
|
|
33
|
+
|
|
14
34
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
35
|
+
var cjsModuleLexer__namespace = /*#__PURE__*/_interopNamespace(cjsModuleLexer);
|
|
36
|
+
var esModuleLexer__namespace = /*#__PURE__*/_interopNamespace(esModuleLexer);
|
|
15
37
|
|
|
16
38
|
const trace = logger.trace.extend('loader');
|
|
17
39
|
|
|
@@ -51,7 +73,17 @@ function renderLanguageLoaderAsync(resourcePath, loadedTranslation) {
|
|
|
51
73
|
);
|
|
52
74
|
};
|
|
53
75
|
}
|
|
54
|
-
|
|
76
|
+
function findExportNames(source, mode) {
|
|
77
|
+
if (mode === 'esm') {
|
|
78
|
+
const [, exports] = esModuleLexer__namespace.parse(source);
|
|
79
|
+
return exports;
|
|
80
|
+
}
|
|
81
|
+
const {
|
|
82
|
+
exports
|
|
83
|
+
} = cjsModuleLexer__namespace.parse(source);
|
|
84
|
+
return exports;
|
|
85
|
+
}
|
|
86
|
+
async function vocabLoader(source) {
|
|
55
87
|
trace(`Using vocab loader for ${this.resourcePath}`);
|
|
56
88
|
const callback = this.async();
|
|
57
89
|
if (!callback) {
|
|
@@ -70,14 +102,35 @@ async function vocabLoader() {
|
|
|
70
102
|
return;
|
|
71
103
|
}
|
|
72
104
|
const renderLanguageLoader = renderLanguageLoaderAsync.call(this, devJsonFilePath, loadedTranslation);
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
export default createTranslationFile({
|
|
78
|
-
${loadedLanguages.map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
|
|
79
|
-
});
|
|
105
|
+
const translations = /* ts */`
|
|
106
|
+
const translations = createTranslationFile({
|
|
107
|
+
${Object.keys(loadedTranslation.languages).map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
|
|
108
|
+
});
|
|
80
109
|
`;
|
|
110
|
+
let result;
|
|
111
|
+
|
|
112
|
+
// this is necessary for the Web Assembly boot
|
|
113
|
+
await esModuleLexer__namespace.init;
|
|
114
|
+
const esmExports = findExportNames(source, 'esm');
|
|
115
|
+
if (esmExports.length > 0) {
|
|
116
|
+
const exportName = esmExports[0];
|
|
117
|
+
trace(`Found ESM export '${exportName}' in ${this.resourcePath}`);
|
|
118
|
+
result = /* ts */`
|
|
119
|
+
import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
|
|
120
|
+
${translations}
|
|
121
|
+
export { translations as ${exportName} };
|
|
122
|
+
`;
|
|
123
|
+
} else {
|
|
124
|
+
// init needs to be called and waited upon
|
|
125
|
+
await cjsModuleLexer__namespace.init();
|
|
126
|
+
const exportName = findExportNames(source, 'cjs')[0];
|
|
127
|
+
trace(`Found CJS export '${exportName}' in ${this.resourcePath}`);
|
|
128
|
+
result = /* ts */`
|
|
129
|
+
const { createLanguage, createTranslationFile } = require('@vocab/webpack/${target}');
|
|
130
|
+
${translations}
|
|
131
|
+
exports.${exportName} = translations;
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
81
134
|
trace('Created translation file', result);
|
|
82
135
|
callback(null, result);
|
|
83
136
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import * as cjsModuleLexer from 'cjs-module-lexer';
|
|
3
|
+
import * as esModuleLexer from 'es-module-lexer';
|
|
2
4
|
import { getDevLanguageFileFromTsFile, loadTranslation } from '@vocab/core';
|
|
3
5
|
import { getChunkName } from '../../chunk-name/dist/vocab-webpack-chunk-name.esm.js';
|
|
4
6
|
import { t as trace$1 } from '../../dist/logger-e1862ea1.esm.js';
|
|
@@ -43,7 +45,17 @@ function renderLanguageLoaderAsync(resourcePath, loadedTranslation) {
|
|
|
43
45
|
);
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
function findExportNames(source, mode) {
|
|
49
|
+
if (mode === 'esm') {
|
|
50
|
+
const [, exports] = esModuleLexer.parse(source);
|
|
51
|
+
return exports;
|
|
52
|
+
}
|
|
53
|
+
const {
|
|
54
|
+
exports
|
|
55
|
+
} = cjsModuleLexer.parse(source);
|
|
56
|
+
return exports;
|
|
57
|
+
}
|
|
58
|
+
async function vocabLoader(source) {
|
|
47
59
|
trace(`Using vocab loader for ${this.resourcePath}`);
|
|
48
60
|
const callback = this.async();
|
|
49
61
|
if (!callback) {
|
|
@@ -62,14 +74,35 @@ async function vocabLoader() {
|
|
|
62
74
|
return;
|
|
63
75
|
}
|
|
64
76
|
const renderLanguageLoader = renderLanguageLoaderAsync.call(this, devJsonFilePath, loadedTranslation);
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export default createTranslationFile({
|
|
70
|
-
${loadedLanguages.map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
|
|
71
|
-
});
|
|
77
|
+
const translations = /* ts */`
|
|
78
|
+
const translations = createTranslationFile({
|
|
79
|
+
${Object.keys(loadedTranslation.languages).map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
|
|
80
|
+
});
|
|
72
81
|
`;
|
|
82
|
+
let result;
|
|
83
|
+
|
|
84
|
+
// this is necessary for the Web Assembly boot
|
|
85
|
+
await esModuleLexer.init;
|
|
86
|
+
const esmExports = findExportNames(source, 'esm');
|
|
87
|
+
if (esmExports.length > 0) {
|
|
88
|
+
const exportName = esmExports[0];
|
|
89
|
+
trace(`Found ESM export '${exportName}' in ${this.resourcePath}`);
|
|
90
|
+
result = /* ts */`
|
|
91
|
+
import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
|
|
92
|
+
${translations}
|
|
93
|
+
export { translations as ${exportName} };
|
|
94
|
+
`;
|
|
95
|
+
} else {
|
|
96
|
+
// init needs to be called and waited upon
|
|
97
|
+
await cjsModuleLexer.init();
|
|
98
|
+
const exportName = findExportNames(source, 'cjs')[0];
|
|
99
|
+
trace(`Found CJS export '${exportName}' in ${this.resourcePath}`);
|
|
100
|
+
result = /* ts */`
|
|
101
|
+
const { createLanguage, createTranslationFile } = require('@vocab/webpack/${target}');
|
|
102
|
+
${translations}
|
|
103
|
+
exports.${exportName} = translations;
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
73
106
|
trace('Created translation file', result);
|
|
74
107
|
callback(null, result);
|
|
75
108
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vocab/webpack",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"main": "dist/vocab-webpack.cjs.js",
|
|
5
5
|
"module": "dist/vocab-webpack.esm.js",
|
|
6
6
|
"exports": {
|
|
@@ -39,10 +39,11 @@
|
|
|
39
39
|
"web"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@vocab/core": "^1.
|
|
43
|
-
"@vocab/types": "^1.1.2",
|
|
42
|
+
"@vocab/core": "^1.3.0",
|
|
44
43
|
"chalk": "^4.1.0",
|
|
44
|
+
"cjs-module-lexer": "^1.2.2",
|
|
45
45
|
"debug": "^4.3.1",
|
|
46
|
+
"es-module-lexer": "^0.9.3",
|
|
46
47
|
"virtual-resource-loader": "^1.0.1"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|