@analogjs/vite-plugin-angular 0.1.1 → 0.2.0-alpha.0
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
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { BundleStylesheetOptions } from '@angular-devkit/build-angular/src/builders/browser-esbuild/stylesheets';
|
|
2
2
|
import * as ts from 'typescript';
|
|
3
3
|
import { Plugin } from 'vite';
|
|
4
|
+
interface PluginOptions {
|
|
5
|
+
tsconfig: string;
|
|
6
|
+
sourcemap: boolean;
|
|
7
|
+
advancedOptimizations: boolean;
|
|
8
|
+
}
|
|
4
9
|
interface EmitFileResult {
|
|
5
10
|
content?: string;
|
|
6
11
|
map?: string;
|
|
@@ -8,10 +13,6 @@ interface EmitFileResult {
|
|
|
8
13
|
hash?: Uint8Array;
|
|
9
14
|
}
|
|
10
15
|
declare type FileEmitter = (file: string) => Promise<EmitFileResult | undefined>;
|
|
11
|
-
export declare function angular(pluginOptions?:
|
|
12
|
-
tsconfig: string;
|
|
13
|
-
sourcemap: boolean;
|
|
14
|
-
advancedOptimizations: boolean;
|
|
15
|
-
}, styleOptions?: BundleStylesheetOptions): Plugin;
|
|
16
|
+
export declare function angular(pluginOptions?: PluginOptions, styleOptions?: BundleStylesheetOptions): Plugin;
|
|
16
17
|
export declare function createFileEmitter(program: ts.BuilderProgram, transformers?: ts.CustomTransformers, onAfterEmit?: (sourceFile: ts.SourceFile) => void): FileEmitter;
|
|
17
18
|
export {};
|
|
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createFileEmitter = exports.angular = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const core_1 = require("@babel/core");
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
6
|
const application_1 = require("@angular-devkit/build-angular/src/babel/presets/application");
|
|
8
|
-
const webpack_loader_1 = require("@angular-devkit/build-angular/src/babel/webpack-loader");
|
|
9
7
|
const ts = require("typescript");
|
|
10
8
|
const compiler_plugin_1 = require("@angular-devkit/build-angular/src/builders/browser-esbuild/compiler-plugin");
|
|
11
9
|
const load_esm_1 = require("@angular-devkit/build-angular/src/utils/load-esm");
|
|
@@ -22,17 +20,19 @@ function angular(pluginOptions = {
|
|
|
22
20
|
let compilerOptions = {};
|
|
23
21
|
// Temporary deep import for transformer support
|
|
24
22
|
const { mergeTransformers, replaceBootstrap, } = require('@ngtools/webpack/src/ivy/transformation');
|
|
25
|
-
const { augmentProgramWithVersioning, } = require('@ngtools/webpack/src/ivy/host');
|
|
23
|
+
const { augmentProgramWithVersioning, augmentHostWithCaching, } = require('@ngtools/webpack/src/ivy/host');
|
|
24
|
+
const { SourceFileCache } = require('@ngtools/webpack/src/ivy/cache');
|
|
26
25
|
let compilerCli;
|
|
27
26
|
let rootNames;
|
|
28
27
|
let host;
|
|
29
28
|
let nextProgram;
|
|
30
29
|
let builderProgram;
|
|
31
|
-
let
|
|
30
|
+
let watchMode = false;
|
|
31
|
+
let sourceFileCache = new SourceFileCache();
|
|
32
32
|
return {
|
|
33
|
-
name: 'vite-plugin-angular',
|
|
33
|
+
name: '@analogjs/vite-plugin-angular',
|
|
34
34
|
config(config, { command }) {
|
|
35
|
-
|
|
35
|
+
watchMode = command === 'serve';
|
|
36
36
|
return {
|
|
37
37
|
optimizeDeps: {
|
|
38
38
|
exclude: ['rxjs'],
|
|
@@ -73,80 +73,35 @@ function angular(pluginOptions = {
|
|
|
73
73
|
rootNames = rn;
|
|
74
74
|
compilerOptions = tsCompilerOptions;
|
|
75
75
|
host = ts.createIncrementalCompilerHost(compilerOptions);
|
|
76
|
+
// Setup source file caching and reuse cache from previous compilation if present
|
|
77
|
+
let cache = new SourceFileCache();
|
|
78
|
+
// Only store cache if in watch mode
|
|
79
|
+
if (watchMode) {
|
|
80
|
+
sourceFileCache = cache;
|
|
81
|
+
}
|
|
82
|
+
augmentHostWithCaching(host, cache);
|
|
83
|
+
yield buildAndAnalyze();
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
handleHotUpdate(ctx) {
|
|
87
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
if (/\.[cm]?tsx?$/.test(ctx.file)) {
|
|
89
|
+
sourceFileCache.invalidate(ctx.file);
|
|
90
|
+
yield buildAndAnalyze();
|
|
91
|
+
}
|
|
76
92
|
});
|
|
77
93
|
},
|
|
78
94
|
transform(code, id) {
|
|
79
|
-
var _a, _b
|
|
95
|
+
var _a, _b;
|
|
80
96
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
// Skip transforming
|
|
82
|
-
if (id.includes('
|
|
97
|
+
// Skip transforming node_modules
|
|
98
|
+
if (id.includes('node_modules')) {
|
|
83
99
|
return;
|
|
84
100
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
const typeScriptProgram = angularProgram.getTsProgram();
|
|
89
|
-
augmentProgramWithVersioning(typeScriptProgram);
|
|
90
|
-
let builder;
|
|
91
|
-
if (mode === 'serve') {
|
|
92
|
-
builder = builderProgram =
|
|
93
|
-
ts.createEmitAndSemanticDiagnosticsBuilderProgram(typeScriptProgram, host, builderProgram);
|
|
94
|
-
nextProgram = angularProgram;
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
// When not in watch mode, the startup cost of the incremental analysis can be avoided by
|
|
98
|
-
// using an abstract builder that only wraps a TypeScript program.
|
|
99
|
-
builder = ts.createAbstractBuilder(typeScriptProgram, host);
|
|
100
|
-
}
|
|
101
|
-
yield angularCompiler.analyzeAsync();
|
|
102
|
-
fileEmitter = createFileEmitter(builder, mergeTransformers(angularCompiler.prepareEmit().transformers, {
|
|
103
|
-
before: [
|
|
104
|
-
replaceBootstrap(() => builder.getProgram().getTypeChecker()),
|
|
105
|
-
],
|
|
106
|
-
}), () => []);
|
|
107
|
-
if (/\.[cm]?js$/.test(id) && id.includes('@angular')) {
|
|
108
|
-
const angularPackage = /[\\/]node_modules[\\/]@angular[\\/]/.test(id);
|
|
109
|
-
const linkerPluginCreator = (yield (0, load_esm_1.loadEsmModule)('@angular/compiler-cli/linker/babel')).createEs2015LinkerPlugin;
|
|
110
|
-
const data = yield fs_1.promises.readFile(id, 'utf-8');
|
|
111
|
-
const result = yield (0, core_1.transformAsync)(data, {
|
|
112
|
-
filename: id,
|
|
113
|
-
inputSourceMap: (pluginOptions.sourcemap
|
|
114
|
-
? undefined
|
|
115
|
-
: false),
|
|
116
|
-
sourceMaps: pluginOptions.sourcemap ? 'inline' : false,
|
|
117
|
-
compact: false,
|
|
118
|
-
configFile: false,
|
|
119
|
-
babelrc: false,
|
|
120
|
-
browserslistConfigFile: false,
|
|
121
|
-
plugins: [],
|
|
122
|
-
presets: [
|
|
123
|
-
[
|
|
124
|
-
application_1.default,
|
|
125
|
-
{
|
|
126
|
-
angularLinker: {
|
|
127
|
-
shouldLink: yield (0, webpack_loader_1.requiresLinking)(id, data),
|
|
128
|
-
jitMode: false,
|
|
129
|
-
linkerPluginCreator,
|
|
130
|
-
},
|
|
131
|
-
forceAsyncTransformation: !/[\\/][_f]?esm2015[\\/]/.test(id) && data.includes('async'),
|
|
132
|
-
optimize: pluginOptions.advancedOptimizations && {
|
|
133
|
-
looseEnums: angularPackage,
|
|
134
|
-
pureTopLevel: angularPackage,
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
],
|
|
138
|
-
],
|
|
139
|
-
});
|
|
140
|
-
return {
|
|
141
|
-
code: (_a = result === null || result === void 0 ? void 0 : result.code) !== null && _a !== void 0 ? _a : data,
|
|
142
|
-
map: result === null || result === void 0 ? void 0 : result.map,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
101
|
+
const typescriptResult = yield fileEmitter(id);
|
|
102
|
+
// return fileEmitter
|
|
103
|
+
const data = (_a = typescriptResult === null || typescriptResult === void 0 ? void 0 : typescriptResult.content) !== null && _a !== void 0 ? _a : '';
|
|
145
104
|
if (/\.[cm]?tsx?$/.test(id)) {
|
|
146
|
-
const typescriptResult = yield fileEmitter(id);
|
|
147
|
-
// return fileEmitter
|
|
148
|
-
const data = (_b = typescriptResult === null || typescriptResult === void 0 ? void 0 : typescriptResult.content) !== null && _b !== void 0 ? _b : '';
|
|
149
|
-
// console.log(id, data);
|
|
150
105
|
const babelResult = yield (0, core_1.transformAsync)(data, {
|
|
151
106
|
filename: id,
|
|
152
107
|
inputSourceMap: (pluginOptions.sourcemap
|
|
@@ -169,16 +124,43 @@ function angular(pluginOptions = {
|
|
|
169
124
|
],
|
|
170
125
|
});
|
|
171
126
|
return {
|
|
172
|
-
code: (
|
|
127
|
+
code: (_b = babelResult === null || babelResult === void 0 ? void 0 : babelResult.code) !== null && _b !== void 0 ? _b : '',
|
|
173
128
|
map: babelResult === null || babelResult === void 0 ? void 0 : babelResult.map,
|
|
174
129
|
};
|
|
175
130
|
}
|
|
176
|
-
return
|
|
177
|
-
code,
|
|
178
|
-
};
|
|
131
|
+
return undefined;
|
|
179
132
|
});
|
|
180
133
|
},
|
|
181
134
|
};
|
|
135
|
+
/**
|
|
136
|
+
* Creates a new NgtscProgram to analyze/re-analyze
|
|
137
|
+
* the source files and create a file emitter.
|
|
138
|
+
* This is shared between an initial build and a hot update.
|
|
139
|
+
*/
|
|
140
|
+
function buildAndAnalyze() {
|
|
141
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
// Create the Angular specific program that contains the Angular compiler
|
|
143
|
+
const angularProgram = new compilerCli.NgtscProgram(rootNames, compilerOptions, host, nextProgram);
|
|
144
|
+
const angularCompiler = angularProgram.compiler;
|
|
145
|
+
const typeScriptProgram = angularProgram.getTsProgram();
|
|
146
|
+
augmentProgramWithVersioning(typeScriptProgram);
|
|
147
|
+
let builder;
|
|
148
|
+
if (watchMode) {
|
|
149
|
+
builder = builderProgram =
|
|
150
|
+
ts.createEmitAndSemanticDiagnosticsBuilderProgram(typeScriptProgram, host, builderProgram);
|
|
151
|
+
nextProgram = angularProgram;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
// When not in watch mode, the startup cost of the incremental analysis can be avoided by
|
|
155
|
+
// using an abstract builder that only wraps a TypeScript program.
|
|
156
|
+
builder = ts.createAbstractBuilder(typeScriptProgram, host);
|
|
157
|
+
}
|
|
158
|
+
yield angularCompiler.analyzeAsync();
|
|
159
|
+
fileEmitter = createFileEmitter(builder, mergeTransformers(angularCompiler.prepareEmit().transformers, {
|
|
160
|
+
before: [replaceBootstrap(() => builder.getProgram().getTypeChecker())],
|
|
161
|
+
}), () => []);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
182
164
|
}
|
|
183
165
|
exports.angular = angular;
|
|
184
166
|
function createFileEmitter(program, transformers = {}, onAfterEmit) {
|
|
@@ -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,
|
|
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;AAEnG,iCAAiC;AAGjC,gHAAkH;AAClH,+EAAiF;AAgBjF,SAAgB,OAAO,CACrB,gBAA+B;IAC7B,QAAQ,EAAE,qBAAqB;IAC/B,SAAS,EAAE,KAAK;IAChB,qBAAqB,EAAE,KAAK;CAC7B,EACD,eAAwC;IACtC,YAAY,EAAE,KAAK;IACnB,SAAS,EAAE,IAAI;CAChB;IAED,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,4BAA4B,EAC5B,sBAAsB,G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