@vocab/webpack 0.0.0-compiled-translation-import-order-20230328231631 → 0.0.0-expose-entry-regex-20230414045557
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 +1 -0
- package/dist/declarations/src/loader.d.ts +4 -7
- 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 +34 -22
- package/loader/dist/vocab-webpack-loader.cjs.prod.js +34 -22
- package/loader/dist/vocab-webpack-loader.esm.js +34 -22
- package/package.json +7 -4
|
@@ -3,6 +3,7 @@ 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,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
async: () => (err: unknown, result?: string) => void;
|
|
6
|
-
}
|
|
7
|
-
export default function vocabLoader(this: LoaderContext): Promise<void>;
|
|
1
|
+
import { UserConfig } from '@vocab/types';
|
|
2
|
+
import type { LoaderContext as WebpackLoaderContext } from 'webpack';
|
|
3
|
+
type LoaderContext = WebpackLoaderContext<UserConfig>;
|
|
4
|
+
export default function vocabLoader(this: LoaderContext, source: string): Promise<void>;
|
|
8
5
|
export {};
|
|
@@ -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,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var path = require('path');
|
|
6
|
+
var mlly = require('mlly');
|
|
6
7
|
var core = require('@vocab/core');
|
|
7
|
-
var loaderUtils = require('loader-utils');
|
|
8
8
|
var chunkName_dist_vocabWebpackChunkName = require('../../chunk-name/dist/vocab-webpack-chunk-name.cjs.dev.js');
|
|
9
9
|
var logger = require('../../dist/logger-65149486.cjs.dev.js');
|
|
10
10
|
require('chalk');
|
|
@@ -15,9 +15,9 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
15
15
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
16
16
|
|
|
17
17
|
const trace = logger.trace.extend('loader');
|
|
18
|
+
|
|
18
19
|
// Resolve virtual-resource-loader dependency from current package
|
|
19
20
|
const virtualResourceLoader = require.resolve('virtual-resource-loader');
|
|
20
|
-
const encodeWithinSingleQuotes = v => v.replace(/'/g, "\\'");
|
|
21
21
|
function createIdentifier(lang, resourcePath, loadedTranslation) {
|
|
22
22
|
var _loadedTranslation$la;
|
|
23
23
|
trace('Creating identifier for language', lang);
|
|
@@ -31,24 +31,34 @@ function createIdentifier(lang, resourcePath, loadedTranslation) {
|
|
|
31
31
|
const fileIdent = path__default["default"].basename(resourcePath, 'translations.json');
|
|
32
32
|
return `./${fileIdent}-${lang}-virtual.json!=!${unloader}!`;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
|
|
35
|
+
// reimplement `stringifyRequest` from loader-utils 2.x
|
|
36
|
+
// https://github.com/webpack/loader-utils/blob/master/CHANGELOG.md#300-2021-10-20
|
|
37
|
+
function stringifyRequest(request) {
|
|
38
|
+
return JSON.stringify(this.utils.contextify(this.context, request));
|
|
39
|
+
}
|
|
40
|
+
function renderLanguageLoaderAsync(resourcePath, loadedTranslation) {
|
|
41
|
+
return lang => {
|
|
42
|
+
const identifier = stringifyRequest.call(this, createIdentifier(lang, resourcePath, loadedTranslation));
|
|
43
|
+
return (/* ts */`
|
|
44
|
+
createLanguage(
|
|
45
|
+
require.resolveWeak(${identifier}),
|
|
46
|
+
() => import(
|
|
47
|
+
/* webpackChunkName: ${JSON.stringify(chunkName_dist_vocabWebpackChunkName.getChunkName(lang))} */
|
|
48
|
+
${identifier}
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
`.trim()
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async function vocabLoader(source) {
|
|
42
56
|
trace(`Using vocab loader for ${this.resourcePath}`);
|
|
43
57
|
const callback = this.async();
|
|
44
58
|
if (!callback) {
|
|
45
59
|
throw new Error(`Webpack didn't provide an async callback`);
|
|
46
60
|
}
|
|
47
|
-
|
|
48
|
-
// @ts-expect-error We define our own loader context type, getOptions expects
|
|
49
|
-
// webpack's LoaderContext type, but it's missing the target field
|
|
50
|
-
// https://github.com/webpack/webpack/issues/16753
|
|
51
|
-
const config = loaderUtils.getOptions(this);
|
|
61
|
+
const config = this.getOptions();
|
|
52
62
|
const devJsonFilePath = core.getDevLanguageFileFromTsFile(this.resourcePath);
|
|
53
63
|
const loadedTranslation = core.loadTranslation({
|
|
54
64
|
filePath: devJsonFilePath,
|
|
@@ -60,15 +70,17 @@ async function vocabLoader() {
|
|
|
60
70
|
callback(new Error('Called Vocab Loader with non-web target'));
|
|
61
71
|
return;
|
|
62
72
|
}
|
|
63
|
-
const renderLanguageLoader = renderLanguageLoaderAsync(devJsonFilePath, loadedTranslation);
|
|
73
|
+
const renderLanguageLoader = renderLanguageLoaderAsync.call(this, devJsonFilePath, loadedTranslation);
|
|
64
74
|
const loadedLanguages = Object.keys(loadedTranslation.languages);
|
|
65
|
-
const
|
|
66
|
-
|
|
75
|
+
const exportName = mlly.findExportNames(source)[0];
|
|
76
|
+
const result = /* ts */`
|
|
77
|
+
import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
|
|
67
78
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
const translation = createTranslationFile({
|
|
80
|
+
${loadedLanguages.map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
|
|
81
|
+
});
|
|
82
|
+
export { translation as ${exportName} };
|
|
83
|
+
`;
|
|
72
84
|
trace('Created translation file', result);
|
|
73
85
|
callback(null, result);
|
|
74
86
|
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var path = require('path');
|
|
6
|
+
var mlly = require('mlly');
|
|
6
7
|
var core = require('@vocab/core');
|
|
7
|
-
var loaderUtils = require('loader-utils');
|
|
8
8
|
var chunkName_dist_vocabWebpackChunkName = require('../../chunk-name/dist/vocab-webpack-chunk-name.cjs.prod.js');
|
|
9
9
|
var logger = require('../../dist/logger-f79e34a8.cjs.prod.js');
|
|
10
10
|
require('chalk');
|
|
@@ -15,9 +15,9 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
15
15
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
16
16
|
|
|
17
17
|
const trace = logger.trace.extend('loader');
|
|
18
|
+
|
|
18
19
|
// Resolve virtual-resource-loader dependency from current package
|
|
19
20
|
const virtualResourceLoader = require.resolve('virtual-resource-loader');
|
|
20
|
-
const encodeWithinSingleQuotes = v => v.replace(/'/g, "\\'");
|
|
21
21
|
function createIdentifier(lang, resourcePath, loadedTranslation) {
|
|
22
22
|
var _loadedTranslation$la;
|
|
23
23
|
trace('Creating identifier for language', lang);
|
|
@@ -31,24 +31,34 @@ function createIdentifier(lang, resourcePath, loadedTranslation) {
|
|
|
31
31
|
const fileIdent = path__default["default"].basename(resourcePath, 'translations.json');
|
|
32
32
|
return `./${fileIdent}-${lang}-virtual.json!=!${unloader}!`;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
|
|
35
|
+
// reimplement `stringifyRequest` from loader-utils 2.x
|
|
36
|
+
// https://github.com/webpack/loader-utils/blob/master/CHANGELOG.md#300-2021-10-20
|
|
37
|
+
function stringifyRequest(request) {
|
|
38
|
+
return JSON.stringify(this.utils.contextify(this.context, request));
|
|
39
|
+
}
|
|
40
|
+
function renderLanguageLoaderAsync(resourcePath, loadedTranslation) {
|
|
41
|
+
return lang => {
|
|
42
|
+
const identifier = stringifyRequest.call(this, createIdentifier(lang, resourcePath, loadedTranslation));
|
|
43
|
+
return (/* ts */`
|
|
44
|
+
createLanguage(
|
|
45
|
+
require.resolveWeak(${identifier}),
|
|
46
|
+
() => import(
|
|
47
|
+
/* webpackChunkName: ${JSON.stringify(chunkName_dist_vocabWebpackChunkName.getChunkName(lang))} */
|
|
48
|
+
${identifier}
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
`.trim()
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async function vocabLoader(source) {
|
|
42
56
|
trace(`Using vocab loader for ${this.resourcePath}`);
|
|
43
57
|
const callback = this.async();
|
|
44
58
|
if (!callback) {
|
|
45
59
|
throw new Error(`Webpack didn't provide an async callback`);
|
|
46
60
|
}
|
|
47
|
-
|
|
48
|
-
// @ts-expect-error We define our own loader context type, getOptions expects
|
|
49
|
-
// webpack's LoaderContext type, but it's missing the target field
|
|
50
|
-
// https://github.com/webpack/webpack/issues/16753
|
|
51
|
-
const config = loaderUtils.getOptions(this);
|
|
61
|
+
const config = this.getOptions();
|
|
52
62
|
const devJsonFilePath = core.getDevLanguageFileFromTsFile(this.resourcePath);
|
|
53
63
|
const loadedTranslation = core.loadTranslation({
|
|
54
64
|
filePath: devJsonFilePath,
|
|
@@ -60,15 +70,17 @@ async function vocabLoader() {
|
|
|
60
70
|
callback(new Error('Called Vocab Loader with non-web target'));
|
|
61
71
|
return;
|
|
62
72
|
}
|
|
63
|
-
const renderLanguageLoader = renderLanguageLoaderAsync(devJsonFilePath, loadedTranslation);
|
|
73
|
+
const renderLanguageLoader = renderLanguageLoaderAsync.call(this, devJsonFilePath, loadedTranslation);
|
|
64
74
|
const loadedLanguages = Object.keys(loadedTranslation.languages);
|
|
65
|
-
const
|
|
66
|
-
|
|
75
|
+
const exportName = mlly.findExportNames(source)[0];
|
|
76
|
+
const result = /* ts */`
|
|
77
|
+
import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
|
|
67
78
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
const translation = createTranslationFile({
|
|
80
|
+
${loadedLanguages.map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
|
|
81
|
+
});
|
|
82
|
+
export { translation as ${exportName} };
|
|
83
|
+
`;
|
|
72
84
|
trace('Created translation file', result);
|
|
73
85
|
callback(null, result);
|
|
74
86
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import { findExportNames } from 'mlly';
|
|
2
3
|
import { getDevLanguageFileFromTsFile, loadTranslation } from '@vocab/core';
|
|
3
|
-
import { getOptions } from 'loader-utils';
|
|
4
4
|
import { getChunkName } from '../../chunk-name/dist/vocab-webpack-chunk-name.esm.js';
|
|
5
5
|
import { t as trace$1 } from '../../dist/logger-e1862ea1.esm.js';
|
|
6
6
|
import 'chalk';
|
|
7
7
|
import 'debug';
|
|
8
8
|
|
|
9
9
|
const trace = trace$1.extend('loader');
|
|
10
|
+
|
|
10
11
|
// Resolve virtual-resource-loader dependency from current package
|
|
11
12
|
const virtualResourceLoader = require.resolve('virtual-resource-loader');
|
|
12
|
-
const encodeWithinSingleQuotes = v => v.replace(/'/g, "\\'");
|
|
13
13
|
function createIdentifier(lang, resourcePath, loadedTranslation) {
|
|
14
14
|
var _loadedTranslation$la;
|
|
15
15
|
trace('Creating identifier for language', lang);
|
|
@@ -23,24 +23,34 @@ function createIdentifier(lang, resourcePath, loadedTranslation) {
|
|
|
23
23
|
const fileIdent = path.basename(resourcePath, 'translations.json');
|
|
24
24
|
return `./${fileIdent}-${lang}-virtual.json!=!${unloader}!`;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
|
|
27
|
+
// reimplement `stringifyRequest` from loader-utils 2.x
|
|
28
|
+
// https://github.com/webpack/loader-utils/blob/master/CHANGELOG.md#300-2021-10-20
|
|
29
|
+
function stringifyRequest(request) {
|
|
30
|
+
return JSON.stringify(this.utils.contextify(this.context, request));
|
|
31
|
+
}
|
|
32
|
+
function renderLanguageLoaderAsync(resourcePath, loadedTranslation) {
|
|
33
|
+
return lang => {
|
|
34
|
+
const identifier = stringifyRequest.call(this, createIdentifier(lang, resourcePath, loadedTranslation));
|
|
35
|
+
return (/* ts */`
|
|
36
|
+
createLanguage(
|
|
37
|
+
require.resolveWeak(${identifier}),
|
|
38
|
+
() => import(
|
|
39
|
+
/* webpackChunkName: ${JSON.stringify(getChunkName(lang))} */
|
|
40
|
+
${identifier}
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
`.trim()
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async function vocabLoader(source) {
|
|
34
48
|
trace(`Using vocab loader for ${this.resourcePath}`);
|
|
35
49
|
const callback = this.async();
|
|
36
50
|
if (!callback) {
|
|
37
51
|
throw new Error(`Webpack didn't provide an async callback`);
|
|
38
52
|
}
|
|
39
|
-
|
|
40
|
-
// @ts-expect-error We define our own loader context type, getOptions expects
|
|
41
|
-
// webpack's LoaderContext type, but it's missing the target field
|
|
42
|
-
// https://github.com/webpack/webpack/issues/16753
|
|
43
|
-
const config = getOptions(this);
|
|
53
|
+
const config = this.getOptions();
|
|
44
54
|
const devJsonFilePath = getDevLanguageFileFromTsFile(this.resourcePath);
|
|
45
55
|
const loadedTranslation = loadTranslation({
|
|
46
56
|
filePath: devJsonFilePath,
|
|
@@ -52,15 +62,17 @@ async function vocabLoader() {
|
|
|
52
62
|
callback(new Error('Called Vocab Loader with non-web target'));
|
|
53
63
|
return;
|
|
54
64
|
}
|
|
55
|
-
const renderLanguageLoader = renderLanguageLoaderAsync(devJsonFilePath, loadedTranslation);
|
|
65
|
+
const renderLanguageLoader = renderLanguageLoaderAsync.call(this, devJsonFilePath, loadedTranslation);
|
|
56
66
|
const loadedLanguages = Object.keys(loadedTranslation.languages);
|
|
57
|
-
const
|
|
58
|
-
|
|
67
|
+
const exportName = findExportNames(source)[0];
|
|
68
|
+
const result = /* ts */`
|
|
69
|
+
import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
|
|
59
70
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
const translation = createTranslationFile({
|
|
72
|
+
${loadedLanguages.map(lang => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(',\n')}
|
|
73
|
+
});
|
|
74
|
+
export { translation as ${exportName} };
|
|
75
|
+
`;
|
|
64
76
|
trace('Created translation file', result);
|
|
65
77
|
callback(null, result);
|
|
66
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vocab/webpack",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-expose-entry-regex-20230414045557",
|
|
4
4
|
"main": "dist/vocab-webpack.cjs.js",
|
|
5
5
|
"module": "dist/vocab-webpack.esm.js",
|
|
6
6
|
"exports": {
|
|
@@ -39,15 +39,18 @@
|
|
|
39
39
|
"web"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@vocab/core": "
|
|
42
|
+
"@vocab/core": "^1.2.5",
|
|
43
43
|
"@vocab/types": "^1.1.2",
|
|
44
44
|
"chalk": "^4.1.0",
|
|
45
45
|
"debug": "^4.3.1",
|
|
46
|
-
"
|
|
46
|
+
"mlly": "^1.2.0",
|
|
47
47
|
"virtual-resource-loader": "^1.0.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/debug": "^4.1.5",
|
|
51
|
-
"
|
|
51
|
+
"webpack": "^5.37.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"webpack": "^5.37.0"
|
|
52
55
|
}
|
|
53
56
|
}
|