@angular-devkit/build-angular 0.1000.0 → 0.1000.4
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/package.json +8 -8
- package/src/angular-cli-files/models/webpack-configs/common.js +9 -1
- package/src/angular-cli-files/plugins/common-js-usage-warn-plugin.d.ts +1 -0
- package/src/angular-cli-files/plugins/common-js-usage-warn-plugin.js +42 -19
- package/src/angular-cli-files/plugins/dedupe-module-resolve-plugin.d.ts +4 -2
- package/src/angular-cli-files/plugins/dedupe-module-resolve-plugin.js +9 -0
- package/src/angular-cli-files/utilities/stats.d.ts +2 -0
- package/src/angular-cli-files/utilities/stats.js +27 -3
- package/src/browser/index.js +26 -16
- package/src/utils/load-translations.js +24 -4
- package/src/utils/process-bundle.js +23 -1
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-devkit/build-angular",
|
|
3
|
-
"version": "0.1000.
|
|
3
|
+
"version": "0.1000.4",
|
|
4
4
|
"description": "Angular Webpack Build Facade",
|
|
5
5
|
"experimental": true,
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"typings": "src/index.d.ts",
|
|
8
8
|
"builders": "builders.json",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@angular-devkit/architect": "0.1000.
|
|
11
|
-
"@angular-devkit/build-optimizer": "0.1000.
|
|
12
|
-
"@angular-devkit/build-webpack": "0.1000.
|
|
13
|
-
"@angular-devkit/core": "10.0.
|
|
10
|
+
"@angular-devkit/architect": "0.1000.4",
|
|
11
|
+
"@angular-devkit/build-optimizer": "0.1000.4",
|
|
12
|
+
"@angular-devkit/build-webpack": "0.1000.4",
|
|
13
|
+
"@angular-devkit/core": "10.0.4",
|
|
14
14
|
"@babel/core": "7.9.6",
|
|
15
15
|
"@babel/generator": "7.9.6",
|
|
16
16
|
"@babel/plugin-transform-runtime": "7.9.6",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"@babel/runtime": "7.9.6",
|
|
19
19
|
"@babel/template": "7.8.6",
|
|
20
20
|
"@jsdevtools/coverage-istanbul-loader": "3.0.3",
|
|
21
|
-
"@ngtools/webpack": "10.0.
|
|
22
|
-
"ajv": "6.12.
|
|
21
|
+
"@ngtools/webpack": "10.0.4",
|
|
22
|
+
"ajv": "6.12.3",
|
|
23
23
|
"autoprefixer": "9.8.0",
|
|
24
24
|
"babel-loader": "8.1.0",
|
|
25
25
|
"browserslist": "^4.9.1",
|
|
26
26
|
"cacache": "15.0.3",
|
|
27
27
|
"caniuse-lite": "^1.0.30001032",
|
|
28
28
|
"circular-dependency-plugin": "5.2.0",
|
|
29
|
-
"copy-webpack-plugin": "6.0.
|
|
29
|
+
"copy-webpack-plugin": "6.0.3",
|
|
30
30
|
"core-js": "3.6.4",
|
|
31
31
|
"css-loader": "3.5.3",
|
|
32
32
|
"cssnano": "4.1.10",
|
|
@@ -226,7 +226,7 @@ function getCommonConfig(wco) {
|
|
|
226
226
|
extraPlugins.push(new (class {
|
|
227
227
|
apply(compiler) {
|
|
228
228
|
compiler.hooks.emit.tap('angular-cli-stats', compilation => {
|
|
229
|
-
const data = JSON.stringify(compilation.getStats().toJson('verbose'));
|
|
229
|
+
const data = JSON.stringify(compilation.getStats().toJson('verbose'), undefined, 2);
|
|
230
230
|
compilation.assets['stats.json'] = new webpack_sources_1.RawSource(data);
|
|
231
231
|
});
|
|
232
232
|
}
|
|
@@ -422,6 +422,13 @@ function getCommonConfig(wco) {
|
|
|
422
422
|
test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/,
|
|
423
423
|
parser: { system: true },
|
|
424
424
|
},
|
|
425
|
+
{
|
|
426
|
+
// Mark files inside `rxjs/add` as containing side effects.
|
|
427
|
+
// If this is fixed upstream and the fixed version becomes the minimum
|
|
428
|
+
// supported version, this can be removed.
|
|
429
|
+
test: /[\/\\]rxjs[\/\\]add[\/\\].+\.js$/,
|
|
430
|
+
sideEffects: true,
|
|
431
|
+
},
|
|
425
432
|
{
|
|
426
433
|
test: /\.m?js$/,
|
|
427
434
|
exclude: [/[\/\\](?:core-js|\@babel|tslib)[\/\\]/, /(ngfactory|ngstyle)\.js$/],
|
|
@@ -440,6 +447,7 @@ function getCommonConfig(wco) {
|
|
|
440
447
|
cacheIdentifier: JSON.stringify({
|
|
441
448
|
buildAngular: require('../../../../package.json').version,
|
|
442
449
|
}),
|
|
450
|
+
sourceType: 'unambiguous',
|
|
443
451
|
presets: [
|
|
444
452
|
[
|
|
445
453
|
require.resolve('@babel/preset-env'),
|
|
@@ -12,40 +12,43 @@ const path_1 = require("path");
|
|
|
12
12
|
// Webpack doesn't export these so the deep imports can potentially break.
|
|
13
13
|
const CommonJsRequireDependency = require('webpack/lib/dependencies/CommonJsRequireDependency');
|
|
14
14
|
const AMDDefineDependency = require('webpack/lib/dependencies/AMDDefineDependency');
|
|
15
|
+
const STYLES_TEMPLATE_URL_REGEXP = /\.(html|svg|css|sass|less|styl|scss)$/;
|
|
15
16
|
class CommonJsUsageWarnPlugin {
|
|
16
17
|
constructor(options = {}) {
|
|
18
|
+
var _a;
|
|
17
19
|
this.options = options;
|
|
18
20
|
this.shownWarnings = new Set();
|
|
19
21
|
// Allow the below depedency for HMR
|
|
20
22
|
// tslint:disable-next-line: max-line-length
|
|
21
23
|
// https://github.com/angular/angular-cli/blob/1e258317b1f6ec1e957ee3559cc3b28ba602f3ba/packages/angular_devkit/build_angular/src/dev-server/index.ts#L605-L638
|
|
22
|
-
this.allowedDepedencies = [
|
|
23
|
-
|
|
24
|
-
];
|
|
25
|
-
if (this.options.allowedDepedencies) {
|
|
26
|
-
this.allowedDepedencies.push(...this.options.allowedDepedencies);
|
|
27
|
-
}
|
|
24
|
+
this.allowedDepedencies = new Set(['webpack/hot/dev-server']);
|
|
25
|
+
(_a = this.options.allowedDepedencies) === null || _a === void 0 ? void 0 : _a.forEach(d => this.allowedDepedencies.add(d));
|
|
28
26
|
}
|
|
29
27
|
apply(compiler) {
|
|
30
28
|
compiler.hooks.compilation.tap('CommonJsUsageWarnPlugin', compilation => {
|
|
31
29
|
compilation.hooks.finishModules.tap('CommonJsUsageWarnPlugin', modules => {
|
|
32
|
-
var _a, _b
|
|
30
|
+
var _a, _b;
|
|
33
31
|
for (const { dependencies, rawRequest, issuer } of modules) {
|
|
34
32
|
if (!rawRequest ||
|
|
35
33
|
rawRequest.startsWith('.') ||
|
|
36
|
-
path_1.isAbsolute(rawRequest)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
path_1.isAbsolute(rawRequest) ||
|
|
35
|
+
this.allowedDepedencies.has(rawRequest) ||
|
|
36
|
+
this.allowedDepedencies.has(this.rawRequestToPackageName(rawRequest)) ||
|
|
37
|
+
rawRequest.startsWith('@angular/common/locales/')) {
|
|
38
|
+
/**
|
|
39
|
+
* Skip when:
|
|
40
|
+
* - module is absolute or relative.
|
|
41
|
+
* - module is allowed even if it's a CommonJS.
|
|
42
|
+
* - module is a locale imported from '@angular/common'.
|
|
43
|
+
*/
|
|
42
44
|
continue;
|
|
43
45
|
}
|
|
44
|
-
if (this.hasCommonJsDependencies(dependencies)) {
|
|
46
|
+
if (this.hasCommonJsDependencies(dependencies, true)) {
|
|
45
47
|
// Dependency is CommonsJS or AMD.
|
|
46
48
|
// Check if it's parent issuer is also a CommonJS dependency.
|
|
47
49
|
// In case it is skip as an warning will be show for the parent CommonJS dependency.
|
|
48
|
-
|
|
50
|
+
const parentDependencies = (_a = issuer === null || issuer === void 0 ? void 0 : issuer.issuer) === null || _a === void 0 ? void 0 : _a.dependencies;
|
|
51
|
+
if (parentDependencies && this.hasCommonJsDependencies(parentDependencies)) {
|
|
49
52
|
continue;
|
|
50
53
|
}
|
|
51
54
|
// Find the main issuer (entry-point).
|
|
@@ -56,8 +59,9 @@ class CommonJsUsageWarnPlugin {
|
|
|
56
59
|
// Only show warnings for modules from main entrypoint.
|
|
57
60
|
// And if the issuer request is not from 'webpack-dev-server', as 'webpack-dev-server'
|
|
58
61
|
// will require CommonJS libraries for live reloading such as 'sockjs-node'.
|
|
59
|
-
if ((mainIssuer === null || mainIssuer === void 0 ? void 0 : mainIssuer.name) === 'main' && !((
|
|
60
|
-
const warning = `${issuer === null || issuer === void 0 ? void 0 : issuer.userRequest} depends on ${rawRequest}.
|
|
62
|
+
if ((mainIssuer === null || mainIssuer === void 0 ? void 0 : mainIssuer.name) === 'main' && !((_b = issuer === null || issuer === void 0 ? void 0 : issuer.userRequest) === null || _b === void 0 ? void 0 : _b.includes('webpack-dev-server'))) {
|
|
63
|
+
const warning = `${issuer === null || issuer === void 0 ? void 0 : issuer.userRequest} depends on '${rawRequest}'. ` +
|
|
64
|
+
'CommonJS or AMD dependencies can cause optimization bailouts.\n' +
|
|
61
65
|
'For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies';
|
|
62
66
|
// Avoid showing the same warning multiple times when in 'watch' mode.
|
|
63
67
|
if (!this.shownWarnings.has(warning)) {
|
|
@@ -70,8 +74,27 @@ class CommonJsUsageWarnPlugin {
|
|
|
70
74
|
});
|
|
71
75
|
});
|
|
72
76
|
}
|
|
73
|
-
hasCommonJsDependencies(dependencies) {
|
|
74
|
-
|
|
77
|
+
hasCommonJsDependencies(dependencies, checkForStylesAndTemplatesCJS = false) {
|
|
78
|
+
for (const dep of dependencies) {
|
|
79
|
+
if (dep instanceof CommonJsRequireDependency) {
|
|
80
|
+
if (checkForStylesAndTemplatesCJS && STYLES_TEMPLATE_URL_REGEXP.test(dep.request)) {
|
|
81
|
+
// Skip in case it's a template or stylesheet
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (dep instanceof AMDDefineDependency) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
rawRequestToPackageName(rawRequest) {
|
|
93
|
+
return rawRequest.startsWith('@')
|
|
94
|
+
// Scoped request ex: @angular/common/locale/en -> @angular/common
|
|
95
|
+
? rawRequest.split('/', 2).join('/')
|
|
96
|
+
// Non-scoped request ex: lodash/isEmpty -> lodash
|
|
97
|
+
: rawRequest.split('/', 1)[0];
|
|
75
98
|
}
|
|
76
99
|
}
|
|
77
100
|
exports.CommonJsUsageWarnPlugin = CommonJsUsageWarnPlugin;
|
|
@@ -13,11 +13,13 @@ interface NormalModuleFactoryRequest {
|
|
|
13
13
|
relativePath: string;
|
|
14
14
|
path: string;
|
|
15
15
|
descriptionFileData: {
|
|
16
|
-
name
|
|
17
|
-
version
|
|
16
|
+
name?: string;
|
|
17
|
+
version?: string;
|
|
18
18
|
};
|
|
19
19
|
descriptionFileRoot: string;
|
|
20
20
|
descriptionFilePath: string;
|
|
21
|
+
directory?: boolean;
|
|
22
|
+
file?: boolean;
|
|
21
23
|
}
|
|
22
24
|
export interface DedupeModuleResolvePluginOptions {
|
|
23
25
|
verbose?: boolean;
|
|
@@ -28,6 +28,15 @@ class DedupeModuleResolvePlugin {
|
|
|
28
28
|
if (request.relativePath !== '.') {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
+
// When either of these properties is undefined. It typically means it's a link.
|
|
32
|
+
// In which case we shouldn't try to dedupe it.
|
|
33
|
+
if (request.file === undefined || request.directory === undefined) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
// Empty name or versions are no valid primary entrypoints of a library
|
|
37
|
+
if (!request.descriptionFileData.name || !request.descriptionFileData.version) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
31
40
|
const moduleId = request.descriptionFileData.name + '@' + request.descriptionFileData.version;
|
|
32
41
|
const prevResolvedModule = this.modules.get(moduleId);
|
|
33
42
|
if (!prevResolvedModule) {
|
|
@@ -12,3 +12,5 @@ export declare function generateBuildStats(hash: string, time: number, colors: b
|
|
|
12
12
|
export declare function statsToString(json: any, statsConfig: any): string;
|
|
13
13
|
export declare function statsWarningsToString(json: any, statsConfig: any): string;
|
|
14
14
|
export declare function statsErrorsToString(json: any, statsConfig: any): string;
|
|
15
|
+
export declare function statsHasErrors(json: any): boolean;
|
|
16
|
+
export declare function statsHasWarnings(json: any): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.statsErrorsToString = exports.statsWarningsToString = exports.statsToString = exports.generateBuildStats = exports.generateBundleStats = exports.formatSize = void 0;
|
|
3
|
+
exports.statsHasWarnings = exports.statsHasErrors = exports.statsErrorsToString = exports.statsWarningsToString = exports.statsToString = exports.generateBuildStats = exports.generateBundleStats = exports.formatSize = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @license
|
|
6
6
|
* Copyright Google Inc. All Rights Reserved.
|
|
@@ -77,7 +77,13 @@ function statsWarningsToString(json, statsConfig) {
|
|
|
77
77
|
const colors = statsConfig.colors;
|
|
78
78
|
const rs = (x) => colors ? reset(x) : x;
|
|
79
79
|
const y = (x) => colors ? bold(yellow(x)) : x;
|
|
80
|
-
|
|
80
|
+
const warnings = [...json.warnings];
|
|
81
|
+
if (json.children) {
|
|
82
|
+
warnings.push(...json.children
|
|
83
|
+
.map((c) => c.warnings)
|
|
84
|
+
.reduce((a, b) => [...a, ...b], []));
|
|
85
|
+
}
|
|
86
|
+
return rs('\n' + warnings
|
|
81
87
|
.map((warning) => `${warning}`)
|
|
82
88
|
.filter((warning) => !ERRONEOUS_WARNINGS.some((erroneous) => erroneous.test(warning)))
|
|
83
89
|
.map((warning) => y(`WARNING in ${warning}`))
|
|
@@ -88,6 +94,24 @@ function statsErrorsToString(json, statsConfig) {
|
|
|
88
94
|
const colors = statsConfig.colors;
|
|
89
95
|
const rs = (x) => colors ? reset(x) : x;
|
|
90
96
|
const r = (x) => colors ? bold(red(x)) : x;
|
|
91
|
-
|
|
97
|
+
const errors = [...json.errors];
|
|
98
|
+
if (json.children) {
|
|
99
|
+
errors.push(...json.children
|
|
100
|
+
.map((c) => c.errors)
|
|
101
|
+
.reduce((a, b) => [...a, ...b], []));
|
|
102
|
+
}
|
|
103
|
+
return rs('\n' + errors
|
|
104
|
+
.map((error) => r(`ERROR in ${error}`))
|
|
105
|
+
.join('\n\n'));
|
|
92
106
|
}
|
|
93
107
|
exports.statsErrorsToString = statsErrorsToString;
|
|
108
|
+
function statsHasErrors(json) {
|
|
109
|
+
var _a;
|
|
110
|
+
return json.errors.length > 0 || !!((_a = json.children) === null || _a === void 0 ? void 0 : _a.some((c) => c.errors.length));
|
|
111
|
+
}
|
|
112
|
+
exports.statsHasErrors = statsHasErrors;
|
|
113
|
+
function statsHasWarnings(json) {
|
|
114
|
+
var _a;
|
|
115
|
+
return json.warnings.length > 0 || !!((_a = json.children) === null || _a === void 0 ? void 0 : _a.some((c) => c.warnings.length));
|
|
116
|
+
}
|
|
117
|
+
exports.statsHasWarnings = statsHasWarnings;
|
package/src/browser/index.js
CHANGED
|
@@ -93,8 +93,19 @@ function getCompilerConfig(wco) {
|
|
|
93
93
|
return {};
|
|
94
94
|
}
|
|
95
95
|
async function initialize(options, context, host, webpackConfigurationTransform) {
|
|
96
|
+
var _a, _b;
|
|
96
97
|
const originalOutputPath = options.outputPath;
|
|
97
|
-
|
|
98
|
+
// Assets are processed directly by the builder except when watching
|
|
99
|
+
const adjustedOptions = options.watch ? options : { ...options, assets: [] };
|
|
100
|
+
const { config, projectRoot, projectSourceRoot, i18n, } = await buildBrowserWebpackConfigFromContext(adjustedOptions, context, host, true);
|
|
101
|
+
// Validate asset option values if processed directly
|
|
102
|
+
if (((_a = options.assets) === null || _a === void 0 ? void 0 : _a.length) && !((_b = adjustedOptions.assets) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
103
|
+
utils_1.normalizeAssetPatterns(options.assets, new core_1.virtualFs.SyncDelegateHost(host), core_1.normalize(context.workspaceRoot), core_1.normalize(projectRoot), projectSourceRoot === undefined ? undefined : core_1.normalize(projectSourceRoot)).forEach(({ output }) => {
|
|
104
|
+
if (output.startsWith('..')) {
|
|
105
|
+
throw new Error('An asset cannot be written to a location outside of the output path.');
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
98
109
|
let transformedConfig;
|
|
99
110
|
if (webpackConfigurationTransform) {
|
|
100
111
|
transformedConfig = await webpackConfigurationTransform(config);
|
|
@@ -152,10 +163,10 @@ function buildWebpackBrowser(options, context, transforms = {}) {
|
|
|
152
163
|
if (!success && useBundleDownleveling) {
|
|
153
164
|
// If using bundle downleveling then there is only one build
|
|
154
165
|
// If it fails show any diagnostic messages and bail
|
|
155
|
-
if (webpackStats
|
|
166
|
+
if (stats_1.statsHasWarnings(webpackStats)) {
|
|
156
167
|
context.logger.warn(stats_1.statsWarningsToString(webpackStats, { colors: true }));
|
|
157
168
|
}
|
|
158
|
-
if (webpackStats
|
|
169
|
+
if (stats_1.statsHasErrors(webpackStats)) {
|
|
159
170
|
context.logger.error(stats_1.statsErrorsToString(webpackStats, { colors: true }));
|
|
160
171
|
}
|
|
161
172
|
return { success };
|
|
@@ -388,16 +399,6 @@ function buildWebpackBrowser(options, context, transforms = {}) {
|
|
|
388
399
|
finally {
|
|
389
400
|
executor.stop();
|
|
390
401
|
}
|
|
391
|
-
// Copy assets
|
|
392
|
-
if (options.assets) {
|
|
393
|
-
try {
|
|
394
|
-
await copy_assets_1.copyAssets(utils_1.normalizeAssetPatterns(options.assets, new core_1.virtualFs.SyncDelegateHost(host), root, core_1.normalize(projectRoot), projectSourceRoot === undefined ? undefined : core_1.normalize(projectSourceRoot)), Array.from(outputPaths.values()), context.workspaceRoot);
|
|
395
|
-
}
|
|
396
|
-
catch (err) {
|
|
397
|
-
context.logger.error('Unable to copy assets: ' + err.message);
|
|
398
|
-
return { success: false };
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
402
|
function generateBundleInfoStats(id, bundle, chunk) {
|
|
402
403
|
return stats_1.generateBundleStats({
|
|
403
404
|
id,
|
|
@@ -448,13 +449,12 @@ function buildWebpackBrowser(options, context, transforms = {}) {
|
|
|
448
449
|
break;
|
|
449
450
|
default:
|
|
450
451
|
assertNever(severity);
|
|
451
|
-
break;
|
|
452
452
|
}
|
|
453
453
|
}
|
|
454
|
-
if (webpackStats
|
|
454
|
+
if (stats_1.statsHasWarnings(webpackStats)) {
|
|
455
455
|
context.logger.warn(stats_1.statsWarningsToString(webpackStats, { colors: true }));
|
|
456
456
|
}
|
|
457
|
-
if (webpackStats
|
|
457
|
+
if (stats_1.statsHasErrors(webpackStats)) {
|
|
458
458
|
context.logger.error(stats_1.statsErrorsToString(webpackStats, { colors: true }));
|
|
459
459
|
return { success: false };
|
|
460
460
|
}
|
|
@@ -471,6 +471,16 @@ function buildWebpackBrowser(options, context, transforms = {}) {
|
|
|
471
471
|
}
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
|
+
// Copy assets
|
|
475
|
+
if (!options.watch && options.assets) {
|
|
476
|
+
try {
|
|
477
|
+
await copy_assets_1.copyAssets(utils_1.normalizeAssetPatterns(options.assets, new core_1.virtualFs.SyncDelegateHost(host), root, core_1.normalize(projectRoot), projectSourceRoot === undefined ? undefined : core_1.normalize(projectSourceRoot)), Array.from(outputPaths.values()), context.workspaceRoot);
|
|
478
|
+
}
|
|
479
|
+
catch (err) {
|
|
480
|
+
context.logger.error('Unable to copy assets: ' + err.message);
|
|
481
|
+
return { success: false };
|
|
482
|
+
}
|
|
483
|
+
}
|
|
474
484
|
if (options.index) {
|
|
475
485
|
for (const [locale, outputPath] of outputPaths.entries()) {
|
|
476
486
|
let localeBaseHref;
|
|
@@ -14,15 +14,35 @@ async function createTranslationLoader() {
|
|
|
14
14
|
const { parsers, diagnostics } = await importParsers();
|
|
15
15
|
return (path) => {
|
|
16
16
|
const content = fs.readFileSync(path, 'utf8');
|
|
17
|
+
const unusedParsers = new Map();
|
|
17
18
|
for (const [format, parser] of Object.entries(parsers)) {
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
const analysis = analyze(parser, path, content);
|
|
20
|
+
if (analysis.canParse) {
|
|
21
|
+
const translationBundle = parser.parse(path, content, analysis.hint);
|
|
20
22
|
const integrity = 'sha256-' + crypto_1.createHash('sha256').update(content).digest('base64');
|
|
21
|
-
return { format, translation:
|
|
23
|
+
return { format, translation: translationBundle.translations, diagnostics, integrity };
|
|
22
24
|
}
|
|
25
|
+
else {
|
|
26
|
+
unusedParsers.set(parser, analysis);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const messages = [];
|
|
30
|
+
for (const [parser, analysis] of unusedParsers.entries()) {
|
|
31
|
+
messages.push(analysis.diagnostics.formatDiagnostics(`*** ${parser.constructor.name} ***`));
|
|
23
32
|
}
|
|
24
|
-
throw new Error(
|
|
33
|
+
throw new Error(`Unsupported translation file format in ${path}. The following parsers were tried:\n` + messages.join('\n'));
|
|
25
34
|
};
|
|
35
|
+
// TODO: `parser.canParse()` is deprecated; remove this polyfill once we are sure all parsers provide the `parser.analyze()` method.
|
|
36
|
+
// tslint:disable-next-line: no-any
|
|
37
|
+
function analyze(parser, path, content) {
|
|
38
|
+
if (parser.analyze !== undefined) {
|
|
39
|
+
return parser.analyze(path, content);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const hint = parser.canParse(path, content);
|
|
43
|
+
return { canParse: hint !== false, hint, diagnostics };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
26
46
|
}
|
|
27
47
|
exports.createTranslationLoader = createTranslationLoader;
|
|
28
48
|
async function importParsers() {
|
|
@@ -91,7 +91,10 @@ async function process(options) {
|
|
|
91
91
|
exclude: ['transform-typeof-symbol'],
|
|
92
92
|
},
|
|
93
93
|
]],
|
|
94
|
-
plugins:
|
|
94
|
+
plugins: [
|
|
95
|
+
createIifeWrapperPlugin(),
|
|
96
|
+
...(options.replacements ? [createReplacePlugin(options.replacements)] : []),
|
|
97
|
+
],
|
|
95
98
|
minified: environment_options_1.allowMinify && !!options.optimize,
|
|
96
99
|
compact: !environment_options_1.shouldBeautify && !!options.optimize,
|
|
97
100
|
sourceMaps: !!sourceMap,
|
|
@@ -335,6 +338,25 @@ function createReplacePlugin(replacements) {
|
|
|
335
338
|
},
|
|
336
339
|
};
|
|
337
340
|
}
|
|
341
|
+
function createIifeWrapperPlugin() {
|
|
342
|
+
return {
|
|
343
|
+
visitor: {
|
|
344
|
+
Program: {
|
|
345
|
+
exit(path) {
|
|
346
|
+
// Save existing body and directives
|
|
347
|
+
const { body, directives } = path.node;
|
|
348
|
+
// Clear out body and directives for wrapper
|
|
349
|
+
path.node.body = [];
|
|
350
|
+
path.node.directives = [];
|
|
351
|
+
// Create the wrapper - "(function() { ... })();"
|
|
352
|
+
const wrapper = core_1.types.expressionStatement(core_1.types.callExpression(core_1.types.parenthesizedExpression(core_1.types.functionExpression(undefined, [], core_1.types.blockStatement(body, directives))), []));
|
|
353
|
+
// Insert the wrapper
|
|
354
|
+
path.pushContainer('body', wrapper);
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
}
|
|
338
360
|
const USE_LOCALIZE_PLUGINS = false;
|
|
339
361
|
async function createI18nPlugins(locale, translation, missingTranslation, localeDataContent) {
|
|
340
362
|
const plugins = [];
|