@vocab/webpack 0.0.0-migrate-pnpm-20230301050934
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/LICENSE +21 -0
- package/chunk-name/dist/vocab-webpack-chunk-name.cjs.d.ts +1 -0
- package/chunk-name/dist/vocab-webpack-chunk-name.cjs.dev.js +9 -0
- package/chunk-name/dist/vocab-webpack-chunk-name.cjs.js +7 -0
- package/chunk-name/dist/vocab-webpack-chunk-name.cjs.prod.js +9 -0
- package/chunk-name/dist/vocab-webpack-chunk-name.esm.js +5 -0
- package/chunk-name/package.json +4 -0
- package/dist/declarations/src/chunk-name.d.ts +1 -0
- package/dist/declarations/src/index.d.ts +11 -0
- package/dist/declarations/src/loader.d.ts +8 -0
- package/dist/declarations/src/logger.d.ts +3 -0
- package/dist/declarations/src/web.d.ts +3 -0
- package/dist/logger-65149486.cjs.dev.js +12 -0
- package/dist/logger-e1862ea1.esm.js +6 -0
- package/dist/logger-f79e34a8.cjs.prod.js +12 -0
- package/dist/vocab-webpack.cjs.d.ts +1 -0
- package/dist/vocab-webpack.cjs.dev.js +41 -0
- package/dist/vocab-webpack.cjs.js +7 -0
- package/dist/vocab-webpack.cjs.prod.js +41 -0
- package/dist/vocab-webpack.esm.js +37 -0
- package/loader/dist/vocab-webpack-loader.cjs.d.ts +2 -0
- package/loader/dist/vocab-webpack-loader.cjs.dev.js +76 -0
- package/loader/dist/vocab-webpack-loader.cjs.js +7 -0
- package/loader/dist/vocab-webpack-loader.cjs.prod.js +76 -0
- package/loader/dist/vocab-webpack-loader.esm.js +68 -0
- package/loader/package.json +4 -0
- package/package.json +53 -0
- package/web/dist/vocab-webpack-web.cjs.d.ts +1 -0
- package/web/dist/vocab-webpack-web.cjs.dev.js +34 -0
- package/web/dist/vocab-webpack-web.cjs.js +7 -0
- package/web/dist/vocab-webpack-web.cjs.prod.js +34 -0
- package/web/dist/vocab-webpack-web.esm.js +26 -0
- package/web/package.json +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
### MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 SEEK
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../dist/declarations/src/chunk-name";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getChunkName(lang: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UserConfig } from '@vocab/types';
|
|
2
|
+
import type { Compiler } from 'webpack';
|
|
3
|
+
interface UserOptions extends Partial<UserConfig> {
|
|
4
|
+
configFile?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class VocabWebpackPlugin {
|
|
7
|
+
options: UserConfig;
|
|
8
|
+
constructor({ configFile, ...rest }?: UserOptions);
|
|
9
|
+
apply(compiler: Compiler): void;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('chalk');
|
|
4
|
+
var debug = require('debug');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
7
|
+
|
|
8
|
+
var debug__default = /*#__PURE__*/_interopDefault(debug);
|
|
9
|
+
|
|
10
|
+
const trace = debug__default["default"](`vocab:webpack`);
|
|
11
|
+
|
|
12
|
+
exports.trace = trace;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('chalk');
|
|
4
|
+
var debug = require('debug');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
7
|
+
|
|
8
|
+
var debug__default = /*#__PURE__*/_interopDefault(debug);
|
|
9
|
+
|
|
10
|
+
const trace = debug__default["default"](`vocab:webpack`);
|
|
11
|
+
|
|
12
|
+
exports.trace = trace;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./declarations/src/index";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@vocab/core');
|
|
6
|
+
var logger = require('./logger-65149486.cjs.dev.js');
|
|
7
|
+
require('chalk');
|
|
8
|
+
require('debug');
|
|
9
|
+
|
|
10
|
+
class VocabWebpackPlugin {
|
|
11
|
+
constructor({
|
|
12
|
+
configFile,
|
|
13
|
+
...rest
|
|
14
|
+
} = {}) {
|
|
15
|
+
logger.trace(`Creating Vocab plugin${configFile ? ` with config file ${configFile}` : ''}`);
|
|
16
|
+
this.options = {
|
|
17
|
+
...core.resolveConfigSync(configFile),
|
|
18
|
+
...rest
|
|
19
|
+
};
|
|
20
|
+
core.validateConfig(this.options);
|
|
21
|
+
}
|
|
22
|
+
apply(compiler) {
|
|
23
|
+
logger.trace(`Applying plugin: ${compiler.options.name} (${compiler.options.target})`);
|
|
24
|
+
if (!compiler.options.module) {
|
|
25
|
+
// @ts-expect-error Support for older versions of webpack that may not have module defined at this stage
|
|
26
|
+
compiler.options.module = {
|
|
27
|
+
rules: []
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (!compiler.options.module.rules) {
|
|
31
|
+
compiler.options.module.rules = [];
|
|
32
|
+
}
|
|
33
|
+
compiler.options.module.rules.splice(0, 0, {
|
|
34
|
+
test: /\.vocab[\\\/]index\.ts$/,
|
|
35
|
+
loader: require.resolve('@vocab/webpack/loader'),
|
|
36
|
+
options: this.options
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.VocabWebpackPlugin = VocabWebpackPlugin;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@vocab/core');
|
|
6
|
+
var logger = require('./logger-f79e34a8.cjs.prod.js');
|
|
7
|
+
require('chalk');
|
|
8
|
+
require('debug');
|
|
9
|
+
|
|
10
|
+
class VocabWebpackPlugin {
|
|
11
|
+
constructor({
|
|
12
|
+
configFile,
|
|
13
|
+
...rest
|
|
14
|
+
} = {}) {
|
|
15
|
+
logger.trace(`Creating Vocab plugin${configFile ? ` with config file ${configFile}` : ''}`);
|
|
16
|
+
this.options = {
|
|
17
|
+
...core.resolveConfigSync(configFile),
|
|
18
|
+
...rest
|
|
19
|
+
};
|
|
20
|
+
core.validateConfig(this.options);
|
|
21
|
+
}
|
|
22
|
+
apply(compiler) {
|
|
23
|
+
logger.trace(`Applying plugin: ${compiler.options.name} (${compiler.options.target})`);
|
|
24
|
+
if (!compiler.options.module) {
|
|
25
|
+
// @ts-expect-error Support for older versions of webpack that may not have module defined at this stage
|
|
26
|
+
compiler.options.module = {
|
|
27
|
+
rules: []
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (!compiler.options.module.rules) {
|
|
31
|
+
compiler.options.module.rules = [];
|
|
32
|
+
}
|
|
33
|
+
compiler.options.module.rules.splice(0, 0, {
|
|
34
|
+
test: /\.vocab[\\\/]index\.ts$/,
|
|
35
|
+
loader: require.resolve('@vocab/webpack/loader'),
|
|
36
|
+
options: this.options
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.VocabWebpackPlugin = VocabWebpackPlugin;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { resolveConfigSync, validateConfig } from '@vocab/core';
|
|
2
|
+
import { t as trace } from './logger-e1862ea1.esm.js';
|
|
3
|
+
import 'chalk';
|
|
4
|
+
import 'debug';
|
|
5
|
+
|
|
6
|
+
class VocabWebpackPlugin {
|
|
7
|
+
constructor({
|
|
8
|
+
configFile,
|
|
9
|
+
...rest
|
|
10
|
+
} = {}) {
|
|
11
|
+
trace(`Creating Vocab plugin${configFile ? ` with config file ${configFile}` : ''}`);
|
|
12
|
+
this.options = {
|
|
13
|
+
...resolveConfigSync(configFile),
|
|
14
|
+
...rest
|
|
15
|
+
};
|
|
16
|
+
validateConfig(this.options);
|
|
17
|
+
}
|
|
18
|
+
apply(compiler) {
|
|
19
|
+
trace(`Applying plugin: ${compiler.options.name} (${compiler.options.target})`);
|
|
20
|
+
if (!compiler.options.module) {
|
|
21
|
+
// @ts-expect-error Support for older versions of webpack that may not have module defined at this stage
|
|
22
|
+
compiler.options.module = {
|
|
23
|
+
rules: []
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (!compiler.options.module.rules) {
|
|
27
|
+
compiler.options.module.rules = [];
|
|
28
|
+
}
|
|
29
|
+
compiler.options.module.rules.splice(0, 0, {
|
|
30
|
+
test: /\.vocab[\\\/]index\.ts$/,
|
|
31
|
+
loader: require.resolve('@vocab/webpack/loader'),
|
|
32
|
+
options: this.options
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { VocabWebpackPlugin };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var core = require('@vocab/core');
|
|
7
|
+
var loaderUtils = require('loader-utils');
|
|
8
|
+
var chunkName_dist_vocabWebpackChunkName = require('../../chunk-name/dist/vocab-webpack-chunk-name.cjs.dev.js');
|
|
9
|
+
var logger = require('../../dist/logger-65149486.cjs.dev.js');
|
|
10
|
+
require('chalk');
|
|
11
|
+
require('debug');
|
|
12
|
+
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
16
|
+
|
|
17
|
+
const trace = logger.trace.extend('loader');
|
|
18
|
+
// Resolve virtual-resource-loader dependency from current package
|
|
19
|
+
const virtualResourceLoader = require.resolve('virtual-resource-loader');
|
|
20
|
+
const encodeWithinSingleQuotes = v => v.replace(/'/g, "\\'");
|
|
21
|
+
function createIdentifier(lang, resourcePath, loadedTranslation) {
|
|
22
|
+
var _loadedTranslation$la;
|
|
23
|
+
trace('Creating identifier for language', lang);
|
|
24
|
+
const languageTranslations = (_loadedTranslation$la = loadedTranslation.languages[lang]) !== null && _loadedTranslation$la !== void 0 ? _loadedTranslation$la : {};
|
|
25
|
+
const langJson = {};
|
|
26
|
+
for (const key of loadedTranslation.keys) {
|
|
27
|
+
langJson[key] = languageTranslations[key].message;
|
|
28
|
+
}
|
|
29
|
+
const base64 = Buffer.from(JSON.stringify(langJson), 'utf-8').toString('base64');
|
|
30
|
+
const unloader = `${virtualResourceLoader}?source=${base64}`;
|
|
31
|
+
const fileIdent = path__default["default"].basename(resourcePath, 'translations.json');
|
|
32
|
+
return `./${fileIdent}-${lang}-virtual.json!=!${unloader}!`;
|
|
33
|
+
}
|
|
34
|
+
const renderLanguageLoaderAsync = (resourcePath, loadedTranslation) => lang => {
|
|
35
|
+
const identifier = createIdentifier(lang, resourcePath, loadedTranslation);
|
|
36
|
+
return `'${encodeWithinSingleQuotes(lang)}': createLanguage(require.resolveWeak('${identifier}'), () => import(
|
|
37
|
+
/* webpackChunkName: "${chunkName_dist_vocabWebpackChunkName.getChunkName(lang)}" */
|
|
38
|
+
'${identifier}'
|
|
39
|
+
))`;
|
|
40
|
+
};
|
|
41
|
+
async function vocabLoader() {
|
|
42
|
+
trace(`Using vocab loader for ${this.resourcePath}`);
|
|
43
|
+
const callback = this.async();
|
|
44
|
+
if (!callback) {
|
|
45
|
+
throw new Error(`Webpack didn't provide an async callback`);
|
|
46
|
+
}
|
|
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);
|
|
52
|
+
const devJsonFilePath = core.getDevLanguageFileFromTsFile(this.resourcePath);
|
|
53
|
+
const loadedTranslation = core.loadTranslation({
|
|
54
|
+
filePath: devJsonFilePath,
|
|
55
|
+
fallbacks: 'all'
|
|
56
|
+
}, config);
|
|
57
|
+
const target = this.target;
|
|
58
|
+
if (target && target !== 'web') {
|
|
59
|
+
trace(`Why are you using the loader on ${target}?`);
|
|
60
|
+
callback(new Error('Called Vocab Loader with non-web target'));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const renderLanguageLoader = renderLanguageLoaderAsync(devJsonFilePath, loadedTranslation);
|
|
64
|
+
const loadedLanguages = Object.keys(loadedTranslation.languages);
|
|
65
|
+
const result = `
|
|
66
|
+
import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
|
|
67
|
+
|
|
68
|
+
export default createTranslationFile({
|
|
69
|
+
${loadedLanguages.map(lang => renderLanguageLoader(lang)).join(',')}
|
|
70
|
+
});
|
|
71
|
+
`;
|
|
72
|
+
trace('Created translation file', result);
|
|
73
|
+
callback(null, result);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
exports["default"] = vocabLoader;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var core = require('@vocab/core');
|
|
7
|
+
var loaderUtils = require('loader-utils');
|
|
8
|
+
var chunkName_dist_vocabWebpackChunkName = require('../../chunk-name/dist/vocab-webpack-chunk-name.cjs.prod.js');
|
|
9
|
+
var logger = require('../../dist/logger-f79e34a8.cjs.prod.js');
|
|
10
|
+
require('chalk');
|
|
11
|
+
require('debug');
|
|
12
|
+
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
16
|
+
|
|
17
|
+
const trace = logger.trace.extend('loader');
|
|
18
|
+
// Resolve virtual-resource-loader dependency from current package
|
|
19
|
+
const virtualResourceLoader = require.resolve('virtual-resource-loader');
|
|
20
|
+
const encodeWithinSingleQuotes = v => v.replace(/'/g, "\\'");
|
|
21
|
+
function createIdentifier(lang, resourcePath, loadedTranslation) {
|
|
22
|
+
var _loadedTranslation$la;
|
|
23
|
+
trace('Creating identifier for language', lang);
|
|
24
|
+
const languageTranslations = (_loadedTranslation$la = loadedTranslation.languages[lang]) !== null && _loadedTranslation$la !== void 0 ? _loadedTranslation$la : {};
|
|
25
|
+
const langJson = {};
|
|
26
|
+
for (const key of loadedTranslation.keys) {
|
|
27
|
+
langJson[key] = languageTranslations[key].message;
|
|
28
|
+
}
|
|
29
|
+
const base64 = Buffer.from(JSON.stringify(langJson), 'utf-8').toString('base64');
|
|
30
|
+
const unloader = `${virtualResourceLoader}?source=${base64}`;
|
|
31
|
+
const fileIdent = path__default["default"].basename(resourcePath, 'translations.json');
|
|
32
|
+
return `./${fileIdent}-${lang}-virtual.json!=!${unloader}!`;
|
|
33
|
+
}
|
|
34
|
+
const renderLanguageLoaderAsync = (resourcePath, loadedTranslation) => lang => {
|
|
35
|
+
const identifier = createIdentifier(lang, resourcePath, loadedTranslation);
|
|
36
|
+
return `'${encodeWithinSingleQuotes(lang)}': createLanguage(require.resolveWeak('${identifier}'), () => import(
|
|
37
|
+
/* webpackChunkName: "${chunkName_dist_vocabWebpackChunkName.getChunkName(lang)}" */
|
|
38
|
+
'${identifier}'
|
|
39
|
+
))`;
|
|
40
|
+
};
|
|
41
|
+
async function vocabLoader() {
|
|
42
|
+
trace(`Using vocab loader for ${this.resourcePath}`);
|
|
43
|
+
const callback = this.async();
|
|
44
|
+
if (!callback) {
|
|
45
|
+
throw new Error(`Webpack didn't provide an async callback`);
|
|
46
|
+
}
|
|
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);
|
|
52
|
+
const devJsonFilePath = core.getDevLanguageFileFromTsFile(this.resourcePath);
|
|
53
|
+
const loadedTranslation = core.loadTranslation({
|
|
54
|
+
filePath: devJsonFilePath,
|
|
55
|
+
fallbacks: 'all'
|
|
56
|
+
}, config);
|
|
57
|
+
const target = this.target;
|
|
58
|
+
if (target && target !== 'web') {
|
|
59
|
+
trace(`Why are you using the loader on ${target}?`);
|
|
60
|
+
callback(new Error('Called Vocab Loader with non-web target'));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const renderLanguageLoader = renderLanguageLoaderAsync(devJsonFilePath, loadedTranslation);
|
|
64
|
+
const loadedLanguages = Object.keys(loadedTranslation.languages);
|
|
65
|
+
const result = `
|
|
66
|
+
import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
|
|
67
|
+
|
|
68
|
+
export default createTranslationFile({
|
|
69
|
+
${loadedLanguages.map(lang => renderLanguageLoader(lang)).join(',')}
|
|
70
|
+
});
|
|
71
|
+
`;
|
|
72
|
+
trace('Created translation file', result);
|
|
73
|
+
callback(null, result);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
exports["default"] = vocabLoader;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { getDevLanguageFileFromTsFile, loadTranslation } from '@vocab/core';
|
|
3
|
+
import { getOptions } from 'loader-utils';
|
|
4
|
+
import { getChunkName } from '../../chunk-name/dist/vocab-webpack-chunk-name.esm.js';
|
|
5
|
+
import { t as trace$1 } from '../../dist/logger-e1862ea1.esm.js';
|
|
6
|
+
import 'chalk';
|
|
7
|
+
import 'debug';
|
|
8
|
+
|
|
9
|
+
const trace = trace$1.extend('loader');
|
|
10
|
+
// Resolve virtual-resource-loader dependency from current package
|
|
11
|
+
const virtualResourceLoader = require.resolve('virtual-resource-loader');
|
|
12
|
+
const encodeWithinSingleQuotes = v => v.replace(/'/g, "\\'");
|
|
13
|
+
function createIdentifier(lang, resourcePath, loadedTranslation) {
|
|
14
|
+
var _loadedTranslation$la;
|
|
15
|
+
trace('Creating identifier for language', lang);
|
|
16
|
+
const languageTranslations = (_loadedTranslation$la = loadedTranslation.languages[lang]) !== null && _loadedTranslation$la !== void 0 ? _loadedTranslation$la : {};
|
|
17
|
+
const langJson = {};
|
|
18
|
+
for (const key of loadedTranslation.keys) {
|
|
19
|
+
langJson[key] = languageTranslations[key].message;
|
|
20
|
+
}
|
|
21
|
+
const base64 = Buffer.from(JSON.stringify(langJson), 'utf-8').toString('base64');
|
|
22
|
+
const unloader = `${virtualResourceLoader}?source=${base64}`;
|
|
23
|
+
const fileIdent = path.basename(resourcePath, 'translations.json');
|
|
24
|
+
return `./${fileIdent}-${lang}-virtual.json!=!${unloader}!`;
|
|
25
|
+
}
|
|
26
|
+
const renderLanguageLoaderAsync = (resourcePath, loadedTranslation) => lang => {
|
|
27
|
+
const identifier = createIdentifier(lang, resourcePath, loadedTranslation);
|
|
28
|
+
return `'${encodeWithinSingleQuotes(lang)}': createLanguage(require.resolveWeak('${identifier}'), () => import(
|
|
29
|
+
/* webpackChunkName: "${getChunkName(lang)}" */
|
|
30
|
+
'${identifier}'
|
|
31
|
+
))`;
|
|
32
|
+
};
|
|
33
|
+
async function vocabLoader() {
|
|
34
|
+
trace(`Using vocab loader for ${this.resourcePath}`);
|
|
35
|
+
const callback = this.async();
|
|
36
|
+
if (!callback) {
|
|
37
|
+
throw new Error(`Webpack didn't provide an async callback`);
|
|
38
|
+
}
|
|
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);
|
|
44
|
+
const devJsonFilePath = getDevLanguageFileFromTsFile(this.resourcePath);
|
|
45
|
+
const loadedTranslation = loadTranslation({
|
|
46
|
+
filePath: devJsonFilePath,
|
|
47
|
+
fallbacks: 'all'
|
|
48
|
+
}, config);
|
|
49
|
+
const target = this.target;
|
|
50
|
+
if (target && target !== 'web') {
|
|
51
|
+
trace(`Why are you using the loader on ${target}?`);
|
|
52
|
+
callback(new Error('Called Vocab Loader with non-web target'));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const renderLanguageLoader = renderLanguageLoaderAsync(devJsonFilePath, loadedTranslation);
|
|
56
|
+
const loadedLanguages = Object.keys(loadedTranslation.languages);
|
|
57
|
+
const result = `
|
|
58
|
+
import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
|
|
59
|
+
|
|
60
|
+
export default createTranslationFile({
|
|
61
|
+
${loadedLanguages.map(lang => renderLanguageLoader(lang)).join(',')}
|
|
62
|
+
});
|
|
63
|
+
`;
|
|
64
|
+
trace('Created translation file', result);
|
|
65
|
+
callback(null, result);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { vocabLoader as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vocab/webpack",
|
|
3
|
+
"version": "0.0.0-migrate-pnpm-20230301050934",
|
|
4
|
+
"main": "dist/vocab-webpack.cjs.js",
|
|
5
|
+
"module": "dist/vocab-webpack.esm.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./package.json": "./package.json",
|
|
8
|
+
".": {
|
|
9
|
+
"module": "./dist/vocab-webpack.esm.js",
|
|
10
|
+
"default": "./dist/vocab-webpack.cjs.js"
|
|
11
|
+
},
|
|
12
|
+
"./chunk-name": {
|
|
13
|
+
"module": "./chunk-name/dist/vocab-webpack-chunk-name.esm.js",
|
|
14
|
+
"default": "./chunk-name/dist/vocab-webpack-chunk-name.cjs.js"
|
|
15
|
+
},
|
|
16
|
+
"./loader": {
|
|
17
|
+
"module": "./loader/dist/vocab-webpack-loader.esm.js",
|
|
18
|
+
"default": "./loader/dist/vocab-webpack-loader.cjs.js"
|
|
19
|
+
},
|
|
20
|
+
"./web": {
|
|
21
|
+
"module": "./web/dist/vocab-webpack-web.esm.js",
|
|
22
|
+
"default": "./web/dist/vocab-webpack-web.cjs.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"author": "SEEK",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"preconstruct": {
|
|
28
|
+
"entrypoints": [
|
|
29
|
+
"index.ts",
|
|
30
|
+
"loader.ts",
|
|
31
|
+
"web.ts",
|
|
32
|
+
"chunk-name.ts"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"chunk-name",
|
|
37
|
+
"dist",
|
|
38
|
+
"loader",
|
|
39
|
+
"web"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@vocab/core": "^1.2.0",
|
|
43
|
+
"@vocab/types": "^1.1.2",
|
|
44
|
+
"chalk": "^4.1.0",
|
|
45
|
+
"debug": "^4.3.1",
|
|
46
|
+
"loader-utils": "^2.0.0",
|
|
47
|
+
"virtual-resource-loader": "^1.0.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/debug": "^4.1.5",
|
|
51
|
+
"@types/loader-utils": "^2.0.1"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../dist/declarations/src/web";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var icuHandler = require('@vocab/core/icu-handler');
|
|
6
|
+
var translationFile = require('@vocab/core/translation-file');
|
|
7
|
+
|
|
8
|
+
const createLanguage = (moduleId, loadImport) => {
|
|
9
|
+
let promiseValue;
|
|
10
|
+
return {
|
|
11
|
+
getValue: locale => {
|
|
12
|
+
// @ts-expect-error Missing webpack types
|
|
13
|
+
if (!__webpack_modules__[moduleId]) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// @ts-expect-error Missing webpack types
|
|
18
|
+
const m = __webpack_require__(moduleId);
|
|
19
|
+
return icuHandler.getParsedICUMessages(m, locale);
|
|
20
|
+
},
|
|
21
|
+
load: () => {
|
|
22
|
+
if (!promiseValue) {
|
|
23
|
+
promiseValue = loadImport();
|
|
24
|
+
}
|
|
25
|
+
return promiseValue;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
Object.defineProperty(exports, 'createTranslationFile', {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return translationFile.createTranslationFile; }
|
|
33
|
+
});
|
|
34
|
+
exports.createLanguage = createLanguage;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var icuHandler = require('@vocab/core/icu-handler');
|
|
6
|
+
var translationFile = require('@vocab/core/translation-file');
|
|
7
|
+
|
|
8
|
+
const createLanguage = (moduleId, loadImport) => {
|
|
9
|
+
let promiseValue;
|
|
10
|
+
return {
|
|
11
|
+
getValue: locale => {
|
|
12
|
+
// @ts-expect-error Missing webpack types
|
|
13
|
+
if (!__webpack_modules__[moduleId]) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// @ts-expect-error Missing webpack types
|
|
18
|
+
const m = __webpack_require__(moduleId);
|
|
19
|
+
return icuHandler.getParsedICUMessages(m, locale);
|
|
20
|
+
},
|
|
21
|
+
load: () => {
|
|
22
|
+
if (!promiseValue) {
|
|
23
|
+
promiseValue = loadImport();
|
|
24
|
+
}
|
|
25
|
+
return promiseValue;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
Object.defineProperty(exports, 'createTranslationFile', {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return translationFile.createTranslationFile; }
|
|
33
|
+
});
|
|
34
|
+
exports.createLanguage = createLanguage;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getParsedICUMessages } from '@vocab/core/icu-handler';
|
|
2
|
+
export { createTranslationFile } from '@vocab/core/translation-file';
|
|
3
|
+
|
|
4
|
+
const createLanguage = (moduleId, loadImport) => {
|
|
5
|
+
let promiseValue;
|
|
6
|
+
return {
|
|
7
|
+
getValue: locale => {
|
|
8
|
+
// @ts-expect-error Missing webpack types
|
|
9
|
+
if (!__webpack_modules__[moduleId]) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// @ts-expect-error Missing webpack types
|
|
14
|
+
const m = __webpack_require__(moduleId);
|
|
15
|
+
return getParsedICUMessages(m, locale);
|
|
16
|
+
},
|
|
17
|
+
load: () => {
|
|
18
|
+
if (!promiseValue) {
|
|
19
|
+
promiseValue = loadImport();
|
|
20
|
+
}
|
|
21
|
+
return promiseValue;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { createLanguage };
|
package/web/package.json
ADDED