@analogjs/vite-plugin-angular 0.2.0-alpha.1 → 0.2.0-alpha.11
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 +4 -1
- package/setup-vitest.d.ts +4 -0
- package/setup-vitest.js +116 -0
- package/setup-vitest.js.map +1 -0
- package/src/lib/angular-vite-plugin.d.ts +4 -3
- package/src/lib/angular-vite-plugin.js +143 -68
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/component-assets-plugin.d.ts +10 -0
- package/src/lib/component-assets-plugin.js +52 -0
- package/src/lib/component-assets-plugin.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@analogjs/vite-plugin-angular",
|
|
3
3
|
"description": "Vite Plugin for Angular",
|
|
4
|
-
"version": "0.2.0-alpha.
|
|
4
|
+
"version": "0.2.0-alpha.11",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"vite",
|
|
7
|
+
"vitest",
|
|
6
8
|
"vite-plugin",
|
|
7
9
|
"angular"
|
|
8
10
|
],
|
|
@@ -18,6 +20,7 @@
|
|
|
18
20
|
},
|
|
19
21
|
"peerDependencies": {
|
|
20
22
|
"@angular-devkit/build-angular": "^14.0.0",
|
|
23
|
+
"zone.js": "~0.11.4",
|
|
21
24
|
"tslib": "^2.0.0"
|
|
22
25
|
},
|
|
23
26
|
"main": "./src/index.js",
|
package/setup-vitest.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("zone.js");
|
|
4
|
+
require("zone.js/dist/sync-test");
|
|
5
|
+
require("zone.js/dist/proxy");
|
|
6
|
+
require("zone.js/testing");
|
|
7
|
+
/**
|
|
8
|
+
* Patch Vitest's describe/test/beforeEach/afterEach functions so test code
|
|
9
|
+
* always runs in a testZone (ProxyZone).
|
|
10
|
+
*/
|
|
11
|
+
/* global Zone */
|
|
12
|
+
const Zone = globalThis['Zone'];
|
|
13
|
+
if (Zone === undefined) {
|
|
14
|
+
throw new Error('Missing: Zone (zone.js)');
|
|
15
|
+
}
|
|
16
|
+
if (globalThis['__vitest_zone_patch__'] === true) {
|
|
17
|
+
throw new Error("'vitest' has already been patched with 'Zone'.");
|
|
18
|
+
}
|
|
19
|
+
globalThis['__vitest_zone_patch__'] = true;
|
|
20
|
+
const SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
|
|
21
|
+
const ProxyZoneSpec = Zone['ProxyZoneSpec'];
|
|
22
|
+
if (SyncTestZoneSpec === undefined) {
|
|
23
|
+
throw new Error('Missing: SyncTestZoneSpec (zone.js/dist/sync-test)');
|
|
24
|
+
}
|
|
25
|
+
if (ProxyZoneSpec === undefined) {
|
|
26
|
+
throw new Error('Missing: ProxyZoneSpec (zone.js/dist/proxy.js)');
|
|
27
|
+
}
|
|
28
|
+
const env = globalThis;
|
|
29
|
+
const ambientZone = Zone.current;
|
|
30
|
+
// Create a synchronous-only zone in which to run `describe` blocks in order to
|
|
31
|
+
// raise an error if any asynchronous operations are attempted
|
|
32
|
+
// inside of a `describe` but outside of a `beforeEach` or `it`.
|
|
33
|
+
const syncZone = ambientZone.fork(new SyncTestZoneSpec('vitest.describe'));
|
|
34
|
+
function wrapDescribeInZone(describeBody) {
|
|
35
|
+
return function (...args) {
|
|
36
|
+
return syncZone.run(describeBody, null, args);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Create a proxy zone in which to run `test` blocks so that the tests function
|
|
40
|
+
// can retroactively install different zones.
|
|
41
|
+
const testProxyZone = ambientZone.fork(new ProxyZoneSpec());
|
|
42
|
+
function wrapTestInZone(testBody) {
|
|
43
|
+
if (testBody === undefined) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const wrappedFunc = function () {
|
|
47
|
+
return testProxyZone.run(testBody, null, arguments);
|
|
48
|
+
};
|
|
49
|
+
try {
|
|
50
|
+
Object.defineProperty(wrappedFunc, 'length', {
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
enumerable: false,
|
|
54
|
+
});
|
|
55
|
+
wrappedFunc.length = testBody.length;
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
return testBody.length === 0
|
|
59
|
+
? () => testProxyZone.run(testBody, null)
|
|
60
|
+
: (done) => testProxyZone.run(testBody, null, [done]);
|
|
61
|
+
}
|
|
62
|
+
return wrappedFunc;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* bind describe method to wrap describe.each function
|
|
66
|
+
*/
|
|
67
|
+
const bindDescribe = (originalVitestFn) => function (...eachArgs) {
|
|
68
|
+
return function (...args) {
|
|
69
|
+
args[1] = wrapDescribeInZone(args[1]);
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
return originalVitestFn.apply(this, eachArgs).apply(this, args);
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* bind test method to wrap test.each function
|
|
76
|
+
*/
|
|
77
|
+
const bindTest = (originalVitestFn) => function (...eachArgs) {
|
|
78
|
+
return function (...args) {
|
|
79
|
+
args[1] = wrapTestInZone(args[1]);
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
return originalVitestFn.apply(this, eachArgs).apply(this, args);
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
['describe'].forEach((methodName) => {
|
|
85
|
+
const originalvitestFn = env[methodName];
|
|
86
|
+
env[methodName] = function (...args) {
|
|
87
|
+
args[1] = wrapDescribeInZone(args[1]);
|
|
88
|
+
return originalvitestFn.apply(this, args);
|
|
89
|
+
};
|
|
90
|
+
env[methodName].each = bindDescribe(originalvitestFn.each);
|
|
91
|
+
if (methodName === 'describe') {
|
|
92
|
+
env[methodName].only = env['fdescribe'];
|
|
93
|
+
env[methodName].skip = env['xdescribe'];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
['test', 'it'].forEach((methodName) => {
|
|
97
|
+
const originalvitestFn = env[methodName];
|
|
98
|
+
env[methodName] = function (...args) {
|
|
99
|
+
args[1] = wrapTestInZone(args[1]);
|
|
100
|
+
return originalvitestFn.apply(this, args);
|
|
101
|
+
};
|
|
102
|
+
env[methodName].each = bindTest(originalvitestFn.each);
|
|
103
|
+
if (methodName === 'test' || methodName === 'it') {
|
|
104
|
+
env[methodName].todo = function (...args) {
|
|
105
|
+
return originalvitestFn.todo.apply(this, args);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].forEach((methodName) => {
|
|
110
|
+
const originalvitestFn = env[methodName];
|
|
111
|
+
env[methodName] = function (...args) {
|
|
112
|
+
args[0] = wrapTestInZone(args[0]);
|
|
113
|
+
return originalvitestFn.apply(this, args);
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=setup-vitest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-vitest.js","sourceRoot":"","sources":["../../../packages/vite-plugin-angular/setup-vitest.ts"],"names":[],"mappings":";;AAAA,mBAAiB;AACjB,kCAAgC;AAChC,8BAA4B;AAC5B,2BAAyB;AAEzB;;;GAGG;AACH,iBAAiB;AACjB,MAAM,IAAI,GAAI,UAAkB,CAAC,MAAM,CAAC,CAAC;AAEzC,IAAI,IAAI,KAAK,SAAS,EAAE;IACtB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;CAC5C;AAED,IAAK,UAAkB,CAAC,uBAAuB,CAAC,KAAK,IAAI,EAAE;IACzD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;CACnE;AAEA,UAAkB,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAC;AACpD,MAAM,gBAAgB,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;AAClD,MAAM,aAAa,GAAG,IAAI,CAAC,eAAe,CAA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AAC,UAAU,CAAC,CAAC;IACzC,GAAG,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,IAAW;QACxC,IAAI,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAElC,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
2
|
import { Plugin } from 'vite';
|
|
3
3
|
interface PluginOptions {
|
|
4
|
-
tsconfig
|
|
5
|
-
|
|
4
|
+
tsconfig?: string;
|
|
5
|
+
workspaceRoot?: string;
|
|
6
|
+
inlineStylesExtension?: string;
|
|
6
7
|
}
|
|
7
8
|
interface EmitFileResult {
|
|
8
9
|
content?: string;
|
|
@@ -11,6 +12,6 @@ interface EmitFileResult {
|
|
|
11
12
|
hash?: Uint8Array;
|
|
12
13
|
}
|
|
13
14
|
declare type FileEmitter = (file: string) => Promise<EmitFileResult | undefined>;
|
|
14
|
-
export declare function angular(
|
|
15
|
+
export declare function angular(options?: PluginOptions): Plugin[];
|
|
15
16
|
export declare function createFileEmitter(program: ts.BuilderProgram, transformers?: ts.CustomTransformers, onAfterEmit?: (sourceFile: ts.SourceFile) => void): FileEmitter;
|
|
16
17
|
export {};
|
|
@@ -9,15 +9,26 @@ const ts = require("typescript");
|
|
|
9
9
|
const compiler_plugin_1 = require("@angular-devkit/build-angular/src/builders/browser-esbuild/compiler-plugin");
|
|
10
10
|
const load_esm_1 = require("@angular-devkit/build-angular/src/utils/load-esm");
|
|
11
11
|
const component_resolvers_1 = require("./component-resolvers");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const component_assets_plugin_1 = require("./component-assets-plugin");
|
|
13
|
+
function angular(options) {
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
/**
|
|
16
|
+
* Normalize plugin options so defaults
|
|
17
|
+
* are used for values not provided.
|
|
18
|
+
*/
|
|
19
|
+
const pluginOptions = {
|
|
20
|
+
tsconfig: ((_a = options === null || options === void 0 ? void 0 : options.tsconfig) !== null && _a !== void 0 ? _a : process.env['NODE_ENV'] === 'test')
|
|
21
|
+
? './tsconfig.spec.json'
|
|
22
|
+
: './tsconfig.app.json',
|
|
23
|
+
workspaceRoot: (_b = options === null || options === void 0 ? void 0 : options.workspaceRoot) !== null && _b !== void 0 ? _b : process.cwd(),
|
|
24
|
+
inlineStylesExtension: (_c = options === null || options === void 0 ? void 0 : options.inlineStylesExtension) !== null && _c !== void 0 ? _c : '',
|
|
25
|
+
};
|
|
16
26
|
// The file emitter created during `onStart` that will be used during the build in `onLoad` callbacks for TS files
|
|
17
27
|
let fileEmitter;
|
|
18
28
|
let compilerOptions = {};
|
|
19
29
|
// Temporary deep import for transformer support
|
|
20
30
|
const { mergeTransformers, replaceBootstrap, } = require('@ngtools/webpack/src/ivy/transformation');
|
|
31
|
+
const { replaceResources, } = require('@ngtools/webpack/src/transformers/replace_resources');
|
|
21
32
|
const { augmentProgramWithVersioning, augmentHostWithCaching, } = require('@ngtools/webpack/src/ivy/host');
|
|
22
33
|
const { SourceFileCache } = require('@ngtools/webpack/src/ivy/cache');
|
|
23
34
|
let compilerCli;
|
|
@@ -27,7 +38,9 @@ function angular(pluginOptions = {
|
|
|
27
38
|
let builderProgram;
|
|
28
39
|
let watchMode = false;
|
|
29
40
|
let sourceFileCache = new SourceFileCache();
|
|
30
|
-
let isProd =
|
|
41
|
+
let isProd = process.env['NODE_ENV'] === 'production';
|
|
42
|
+
let isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];
|
|
43
|
+
let viteServer;
|
|
31
44
|
return [
|
|
32
45
|
{
|
|
33
46
|
name: '@analogjs/vite-plugin-angular',
|
|
@@ -44,7 +57,8 @@ function angular(pluginOptions = {
|
|
|
44
57
|
sourcemap: !isProd,
|
|
45
58
|
advancedOptimizations: isProd,
|
|
46
59
|
}, {
|
|
47
|
-
|
|
60
|
+
workspaceRoot: pluginOptions.workspaceRoot,
|
|
61
|
+
sourcemap: !isProd,
|
|
48
62
|
optimization: isProd,
|
|
49
63
|
}),
|
|
50
64
|
],
|
|
@@ -58,34 +72,18 @@ function angular(pluginOptions = {
|
|
|
58
72
|
};
|
|
59
73
|
});
|
|
60
74
|
},
|
|
75
|
+
configureServer(server) {
|
|
76
|
+
viteServer = server;
|
|
77
|
+
server.watcher.on('add', setupCompilation);
|
|
78
|
+
server.watcher.on('unlink', setupCompilation);
|
|
79
|
+
},
|
|
61
80
|
buildStart() {
|
|
62
81
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
|
|
64
|
-
enableIvy: true,
|
|
65
|
-
noEmitOnError: false,
|
|
66
|
-
suppressOutputPathCheck: true,
|
|
67
|
-
outDir: undefined,
|
|
68
|
-
inlineSources: !isProd,
|
|
69
|
-
inlineSourceMap: !isProd,
|
|
70
|
-
sourceMap: false,
|
|
71
|
-
mapRoot: undefined,
|
|
72
|
-
sourceRoot: undefined,
|
|
73
|
-
declaration: false,
|
|
74
|
-
declarationMap: false,
|
|
75
|
-
allowEmptyCodegenFiles: false,
|
|
76
|
-
annotationsAs: 'decorators',
|
|
77
|
-
enableResourceInlining: false,
|
|
78
|
-
});
|
|
79
|
-
rootNames = rn;
|
|
80
|
-
compilerOptions = tsCompilerOptions;
|
|
81
|
-
host = ts.createIncrementalCompilerHost(compilerOptions);
|
|
82
|
-
// Setup source file caching and reuse cache from previous compilation if present
|
|
83
|
-
let cache = new SourceFileCache();
|
|
82
|
+
setupCompilation();
|
|
84
83
|
// Only store cache if in watch mode
|
|
85
84
|
if (watchMode) {
|
|
86
|
-
sourceFileCache
|
|
85
|
+
augmentHostWithCaching(host, sourceFileCache);
|
|
87
86
|
}
|
|
88
|
-
augmentHostWithCaching(host, cache);
|
|
89
87
|
yield buildAndAnalyze();
|
|
90
88
|
});
|
|
91
89
|
},
|
|
@@ -96,6 +94,14 @@ function angular(pluginOptions = {
|
|
|
96
94
|
yield buildAndAnalyze();
|
|
97
95
|
}
|
|
98
96
|
if (/\.(html|htm|css|less|sass|scss)$/.test(ctx.file)) {
|
|
97
|
+
/**
|
|
98
|
+
* Check to see if this was a direct request
|
|
99
|
+
* for an external resource (styles, html).
|
|
100
|
+
*/
|
|
101
|
+
const isDirect = ctx.modules.find((mod) => { var _a; return ctx.file === mod.file && ((_a = mod.id) === null || _a === void 0 ? void 0 : _a.includes('?direct')); });
|
|
102
|
+
if (isDirect) {
|
|
103
|
+
return ctx.modules;
|
|
104
|
+
}
|
|
99
105
|
let mods = [];
|
|
100
106
|
ctx.modules.forEach((mod) => {
|
|
101
107
|
mod.importers.forEach((imp) => {
|
|
@@ -118,24 +124,48 @@ function angular(pluginOptions = {
|
|
|
118
124
|
return;
|
|
119
125
|
}
|
|
120
126
|
if (/\.[cm]?tsx?$/.test(id)) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Re-analyze on each transform
|
|
129
|
+
* for test(Vitest)
|
|
130
|
+
*/
|
|
131
|
+
if (isTest) {
|
|
132
|
+
const tsMod = viteServer.moduleGraph.getModuleById(id);
|
|
133
|
+
if (tsMod) {
|
|
134
|
+
sourceFileCache.invalidate(id);
|
|
135
|
+
yield buildAndAnalyze();
|
|
125
136
|
}
|
|
126
137
|
}
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
138
|
+
if (watchMode) {
|
|
139
|
+
if ((0, component_resolvers_1.hasTemplateUrl)(code)) {
|
|
140
|
+
const templateUrl = (0, component_resolvers_1.resolveTemplateUrl)(code, id);
|
|
141
|
+
if (templateUrl) {
|
|
142
|
+
this.addWatchFile(templateUrl);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if ((0, component_resolvers_1.hasStyleUrls)(code)) {
|
|
146
|
+
const styleUrls = (0, component_resolvers_1.resolveStyleUrls)(code, id);
|
|
147
|
+
styleUrls.forEach((styleUrl) => {
|
|
148
|
+
this.addWatchFile(styleUrl);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
132
151
|
}
|
|
133
152
|
const typescriptResult = yield fileEmitter(id);
|
|
134
153
|
// return fileEmitter
|
|
135
154
|
const data = (_a = typescriptResult === null || typescriptResult === void 0 ? void 0 : typescriptResult.content) !== null && _a !== void 0 ? _a : '';
|
|
155
|
+
const forceAsyncTransformation = /for\s+await\s*\(|async\s+function\s*\*/.test(data);
|
|
156
|
+
const useInputSourcemap = (!isProd ? undefined : false);
|
|
157
|
+
if (!forceAsyncTransformation && !isProd) {
|
|
158
|
+
return {
|
|
159
|
+
code: isProd
|
|
160
|
+
? data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '')
|
|
161
|
+
: data,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
136
164
|
const babelResult = yield (0, core_1.transformAsync)(data, {
|
|
137
165
|
filename: id,
|
|
138
|
-
inputSourceMap: (
|
|
166
|
+
inputSourceMap: (useInputSourcemap
|
|
167
|
+
? undefined
|
|
168
|
+
: false),
|
|
139
169
|
sourceMaps: !isProd ? 'inline' : false,
|
|
140
170
|
compact: false,
|
|
141
171
|
configFile: false,
|
|
@@ -146,7 +176,7 @@ function angular(pluginOptions = {
|
|
|
146
176
|
[
|
|
147
177
|
application_1.default,
|
|
148
178
|
{
|
|
149
|
-
forceAsyncTransformation
|
|
179
|
+
forceAsyncTransformation,
|
|
150
180
|
optimize: isProd && {},
|
|
151
181
|
},
|
|
152
182
|
],
|
|
@@ -166,27 +196,39 @@ function angular(pluginOptions = {
|
|
|
166
196
|
apply: 'build',
|
|
167
197
|
config() {
|
|
168
198
|
return {
|
|
199
|
+
build: {
|
|
200
|
+
rollupOptions: {
|
|
201
|
+
external: [/ngResource/],
|
|
202
|
+
onwarn: (warning, warn) => {
|
|
203
|
+
if (warning.message.includes('ngResource')) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
warn(warning);
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
169
210
|
esbuild: {
|
|
170
|
-
minify: isProd,
|
|
171
|
-
minifyIdentifiers: true,
|
|
172
|
-
minifySyntax: true,
|
|
173
|
-
// NOTE: Disabling whitespace ensures unused pure annotations are kept
|
|
174
|
-
minifyWhitespace: false,
|
|
175
|
-
pure: ['forwardRef'],
|
|
176
211
|
legalComments: 'none',
|
|
177
|
-
// sourcefile: 'name',
|
|
178
|
-
sourcemap: !isProd,
|
|
179
|
-
define: {
|
|
180
|
-
ngDevMode: 'false',
|
|
181
|
-
ngJitMode: 'false',
|
|
182
|
-
ngI18nClosureMode: 'false',
|
|
183
|
-
},
|
|
184
|
-
// This option should always be disabled for browser builds as we don't rely on `.name`
|
|
185
|
-
// and causes deadcode to be retained which makes `NG_BUILD_MANGLE` unusable to investigate tree-shaking issues.
|
|
186
|
-
// We enable `keepNames` only for server builds as Domino relies on `.name`.
|
|
187
|
-
// Once we no longer rely on Domino for SSR we should be able to remove this.
|
|
188
212
|
keepNames: false,
|
|
189
|
-
|
|
213
|
+
define: isProd
|
|
214
|
+
? {
|
|
215
|
+
ngDevMode: 'false',
|
|
216
|
+
ngJitMode: 'false',
|
|
217
|
+
ngI18nClosureMode: 'false',
|
|
218
|
+
}
|
|
219
|
+
: undefined,
|
|
220
|
+
supported: {
|
|
221
|
+
// Native async/await is not supported with Zone.js. Disabling support here will cause
|
|
222
|
+
// esbuild to downlevel async/await to a Zone.js supported form.
|
|
223
|
+
'async-await': false,
|
|
224
|
+
// Zone.js also does not support async generators or async iterators. However, esbuild does
|
|
225
|
+
// not currently support downleveling either of them. Instead babel is used within the JS/TS
|
|
226
|
+
// loader to perform the downlevel transformation. They are both disabled here to allow
|
|
227
|
+
// esbuild to handle them in the future if support is ever added.
|
|
228
|
+
// NOTE: If esbuild adds support in the future, the babel support for these can be disabled.
|
|
229
|
+
'async-generator': false,
|
|
230
|
+
'for-await': false,
|
|
231
|
+
},
|
|
190
232
|
},
|
|
191
233
|
};
|
|
192
234
|
},
|
|
@@ -195,12 +237,20 @@ function angular(pluginOptions = {
|
|
|
195
237
|
if (/\.[cm]?js$/.test(id)) {
|
|
196
238
|
const angularPackage = /[\\/]node_modules[\\/]@angular[\\/]/.test(id);
|
|
197
239
|
const linkerPluginCreator = (yield (0, load_esm_1.loadEsmModule)('@angular/compiler-cli/linker/babel')).createEs2015LinkerPlugin;
|
|
198
|
-
const
|
|
240
|
+
const forceAsyncTransformation = !/[\\/][_f]?esm2015[\\/]/.test(id) &&
|
|
241
|
+
/for\s+await\s*\(|async\s+function\s*\*/.test(code);
|
|
242
|
+
const shouldLink = yield (0, webpack_loader_1.requiresLinking)(id, code);
|
|
243
|
+
const useInputSourcemap = (!isProd ? undefined : false);
|
|
244
|
+
if (!forceAsyncTransformation && !isProd && !shouldLink) {
|
|
245
|
+
return {
|
|
246
|
+
code: isProd
|
|
247
|
+
? code.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '')
|
|
248
|
+
: code,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
199
251
|
const result = yield (0, core_1.transformAsync)(code, {
|
|
200
252
|
filename: id,
|
|
201
|
-
inputSourceMap:
|
|
202
|
-
? undefined
|
|
203
|
-
: false),
|
|
253
|
+
inputSourceMap: useInputSourcemap,
|
|
204
254
|
sourceMaps: !isProd ? 'inline' : false,
|
|
205
255
|
compact: false,
|
|
206
256
|
configFile: false,
|
|
@@ -212,12 +262,11 @@ function angular(pluginOptions = {
|
|
|
212
262
|
application_1.default,
|
|
213
263
|
{
|
|
214
264
|
angularLinker: {
|
|
215
|
-
shouldLink
|
|
265
|
+
shouldLink,
|
|
216
266
|
jitMode: false,
|
|
217
267
|
linkerPluginCreator,
|
|
218
268
|
},
|
|
219
|
-
forceAsyncTransformation
|
|
220
|
-
code.includes('async'),
|
|
269
|
+
forceAsyncTransformation,
|
|
221
270
|
optimize: isProd && {
|
|
222
271
|
looseEnums: angularPackage,
|
|
223
272
|
pureTopLevel: angularPackage,
|
|
@@ -235,7 +284,29 @@ function angular(pluginOptions = {
|
|
|
235
284
|
});
|
|
236
285
|
},
|
|
237
286
|
},
|
|
287
|
+
(0, component_assets_plugin_1.componentAssetsPlugin)(pluginOptions.inlineStylesExtension),
|
|
238
288
|
];
|
|
289
|
+
function setupCompilation() {
|
|
290
|
+
const { options: tsCompilerOptions, rootNames: rn } = compilerCli.readConfiguration(pluginOptions.tsconfig, {
|
|
291
|
+
enableIvy: true,
|
|
292
|
+
noEmitOnError: false,
|
|
293
|
+
suppressOutputPathCheck: true,
|
|
294
|
+
outDir: undefined,
|
|
295
|
+
inlineSources: !isProd,
|
|
296
|
+
inlineSourceMap: !isProd,
|
|
297
|
+
sourceMap: false,
|
|
298
|
+
mapRoot: undefined,
|
|
299
|
+
sourceRoot: undefined,
|
|
300
|
+
declaration: false,
|
|
301
|
+
declarationMap: false,
|
|
302
|
+
allowEmptyCodegenFiles: false,
|
|
303
|
+
annotationsAs: 'decorators',
|
|
304
|
+
enableResourceInlining: false,
|
|
305
|
+
});
|
|
306
|
+
rootNames = rn;
|
|
307
|
+
compilerOptions = tsCompilerOptions;
|
|
308
|
+
host = ts.createIncrementalCompilerHost(compilerOptions);
|
|
309
|
+
}
|
|
239
310
|
/**
|
|
240
311
|
* Creates a new NgtscProgram to analyze/re-analyze
|
|
241
312
|
* the source files and create a file emitter.
|
|
@@ -260,9 +331,13 @@ function angular(pluginOptions = {
|
|
|
260
331
|
builder = ts.createAbstractBuilder(typeScriptProgram, host);
|
|
261
332
|
}
|
|
262
333
|
yield angularCompiler.analyzeAsync();
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
334
|
+
const getTypeChecker = () => builder.getProgram().getTypeChecker();
|
|
335
|
+
fileEmitter = createFileEmitter(builder, mergeTransformers({
|
|
336
|
+
before: [
|
|
337
|
+
replaceBootstrap(getTypeChecker),
|
|
338
|
+
replaceResources(() => true, getTypeChecker, pluginOptions.inlineStylesExtension),
|
|
339
|
+
],
|
|
340
|
+
}, angularCompiler.prepareEmit().transformers), () => []);
|
|
266
341
|
});
|
|
267
342
|
}
|
|
268
343
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angular-vite-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts"],"names":[],"mappings":";;;;AACA,sCAA6C;AAC7C,6FAAmG;AACnG,2FAAyF;
|
|
1
|
+
{"version":3,"file":"angular-vite-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts"],"names":[],"mappings":";;;;AACA,sCAA6C;AAC7C,6FAAmG;AACnG,2FAAyF;AACzF,iCAAiC;AAGjC,gHAAkH;AAClH,+EAAiF;AACjF,+DAK+B;AAC/B,uEAAkE;AAgBlE,SAAgB,OAAO,CAAC,OAAuB;;IAC7C;;;OAGG;IACH,MAAM,aAAa,GAAG;QACpB,QAAQ,EACN,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,MAAM;YACrD,CAAC,CAAC,sBAAsB;YACxB,CAAC,CAAC,qBAAqB;QAC3B,aAAa,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,mCAAI,OAAO,CAAC,GAAG,EAAE;QACtD,qBAAqB,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,qBAAqB,mCAAI,EAAE;KAC5D,CAAC;IAEF,kHAAkH;IAClH,IAAI,WAAoC,CAAC;IACzC,IAAI,eAAe,GAAG,EAAE,CAAC;IACzB,gDAAgD;IAChD,MAAM,EACJ,iBAAiB,EACjB,gBAAgB,GACjB,GAAG,OAAO,CAAC,yCAAyC,CAAC,CAAC;IACvD,MAAM,EACJ,gBAAgB,GACjB,GAAG,OAA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AAS,CAAC,sBAAsB,EAChC,YAAY,CACb,CAAC;QAEF,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAG,UAAU,CAAC,CAAC;QAE1B,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;IACvC,CAAC,CAAA,CAAC;AACJ,CAAC;AA5BD,8CA4BC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* This plugin decodes and returns component assets that were
|
|
4
|
+
* extracted from the Component decorator metadata and encoded
|
|
5
|
+
* into the import string. This allows Vite to intercept
|
|
6
|
+
* these imports, convert them into virtual modules, and
|
|
7
|
+
* return them as imported assets to pass through the appropriate
|
|
8
|
+
* transform pipeline.
|
|
9
|
+
*/
|
|
10
|
+
export declare function componentAssetsPlugin(inlineStylesExtension?: string): Plugin;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.componentAssetsPlugin = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const virtualModuleId = 'virtual:analog-components-assets-module';
|
|
6
|
+
/**
|
|
7
|
+
* This plugin decodes and returns component assets that were
|
|
8
|
+
* extracted from the Component decorator metadata and encoded
|
|
9
|
+
* into the import string. This allows Vite to intercept
|
|
10
|
+
* these imports, convert them into virtual modules, and
|
|
11
|
+
* return them as imported assets to pass through the appropriate
|
|
12
|
+
* transform pipeline.
|
|
13
|
+
*/
|
|
14
|
+
function componentAssetsPlugin(inlineStylesExtension = '') {
|
|
15
|
+
return {
|
|
16
|
+
name: '@analogjs/vite-plugin-angular-component-assets',
|
|
17
|
+
enforce: 'pre',
|
|
18
|
+
resolveId(id) {
|
|
19
|
+
if (id.includes('html?ngResource') && !id.includes(virtualModuleId)) {
|
|
20
|
+
return '\0' + virtualModuleId + id;
|
|
21
|
+
}
|
|
22
|
+
if (id.includes(`.${inlineStylesExtension}?ngResource`) &&
|
|
23
|
+
/data=(.*)\!/.test(id)) {
|
|
24
|
+
return '\0' + virtualModuleId + id;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
},
|
|
28
|
+
load(id) {
|
|
29
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
if (!id.startsWith(`\0${virtualModuleId}`)) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if (id.includes(`.html`)) {
|
|
34
|
+
return `export default "${id
|
|
35
|
+
.replace('\x00', '')
|
|
36
|
+
.replace(virtualModuleId, '')}"`;
|
|
37
|
+
}
|
|
38
|
+
if (id.includes(`.${inlineStylesExtension}?ngResource`) &&
|
|
39
|
+
/data=(.*)\!/.test(id)) {
|
|
40
|
+
const encodedStyles = id.match(/data=(.*)\!/)[1];
|
|
41
|
+
const styles = Buffer.from(decodeURIComponent(encodedStyles), 'base64').toString();
|
|
42
|
+
return {
|
|
43
|
+
code: styles,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.componentAssetsPlugin = componentAssetsPlugin;
|
|
52
|
+
//# sourceMappingURL=component-assets-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-assets-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/component-assets-plugin.ts"],"names":[],"mappings":";;;;AAEA,MAAM,eAAe,GAAG,yCAAyC,CAAC;AAElE;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CAAC,qBAAqB,GAAG,EAAE;IAC9D,OAAO;QACL,IAAI,EAAE,gDAAgD;QACtD,OAAO,EAAE,KAAK;QACd,SAAS,CAAC,EAAE;YACV,IAAI,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,eAAe,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