@embroider/compat 3.5.7 → 3.6.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 +4 -3
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -1
- package/src/index.js.map +1 -1
- package/src/template-tag-codemod.d.ts +10 -0
- package/src/template-tag-codemod.js +258 -0
- package/src/template-tag-codemod.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embroider/compat",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Backward compatibility layer for the Embroider build system.",
|
|
6
6
|
"repository": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@babel/code-frame": "^7.14.5",
|
|
24
24
|
"@babel/core": "^7.14.5",
|
|
25
|
+
"@babel/plugin-syntax-decorators": "^7.24.7",
|
|
25
26
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
26
27
|
"@babel/plugin-transform-runtime": "^7.14.5",
|
|
27
28
|
"@babel/preset-env": "^7.14.5",
|
|
@@ -83,9 +84,9 @@
|
|
|
83
84
|
"ember-engines": "^0.8.19",
|
|
84
85
|
"scenario-tester": "^2.1.2",
|
|
85
86
|
"typescript": "^5.1.6",
|
|
87
|
+
"@embroider/test-support": "0.36.0",
|
|
86
88
|
"@embroider/core": "^3.4.14",
|
|
87
|
-
"@embroider/sample-transforms": "0.0.0"
|
|
88
|
-
"@embroider/test-support": "0.36.0"
|
|
89
|
+
"@embroider/sample-transforms": "0.0.0"
|
|
89
90
|
},
|
|
90
91
|
"peerDependencies": {
|
|
91
92
|
"@embroider/core": "^3.4.14"
|
package/src/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { default as Addons } from './compat-addons';
|
|
|
3
3
|
export { default as Options, recommendedOptions } from './options';
|
|
4
4
|
export { default as V1Addon } from './v1-addon';
|
|
5
5
|
export { default as compatBuild, PipelineOptions } from './default-pipeline';
|
|
6
|
+
export { default as templateTagCodemod } from './template-tag-codemod';
|
|
6
7
|
export { PackageRules, ModuleRules } from './dependency-rules';
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.compatBuild = exports.V1Addon = exports.recommendedOptions = exports.Addons = exports.App = void 0;
|
|
6
|
+
exports.templateTagCodemod = exports.compatBuild = exports.V1Addon = exports.recommendedOptions = exports.Addons = exports.App = void 0;
|
|
7
7
|
var compat_app_1 = require("./compat-app");
|
|
8
8
|
Object.defineProperty(exports, "App", { enumerable: true, get: function () { return __importDefault(compat_app_1).default; } });
|
|
9
9
|
var compat_addons_1 = require("./compat-addons");
|
|
@@ -14,4 +14,6 @@ var v1_addon_1 = require("./v1-addon");
|
|
|
14
14
|
Object.defineProperty(exports, "V1Addon", { enumerable: true, get: function () { return __importDefault(v1_addon_1).default; } });
|
|
15
15
|
var default_pipeline_1 = require("./default-pipeline");
|
|
16
16
|
Object.defineProperty(exports, "compatBuild", { enumerable: true, get: function () { return __importDefault(default_pipeline_1).default; } });
|
|
17
|
+
var template_tag_codemod_1 = require("./template-tag-codemod");
|
|
18
|
+
Object.defineProperty(exports, "templateTagCodemod", { enumerable: true, get: function () { return __importDefault(template_tag_codemod_1).default; } });
|
|
17
19
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA8C;AAArC,kHAAA,OAAO,OAAO;AACvB,iDAAoD;AAA3C,wHAAA,OAAO,OAAU;AAC1B,qCAAmE;AAAtC,6GAAA,kBAAkB,OAAA;AAC/C,uCAAgD;AAAvC,oHAAA,OAAO,OAAW;AAC3B,uDAA6E;AAApE,gIAAA,OAAO,OAAe","sourcesContent":["export { default as App } from './compat-app';\nexport { default as Addons } from './compat-addons';\nexport { default as Options, recommendedOptions } from './options';\nexport { default as V1Addon } from './v1-addon';\nexport { default as compatBuild, PipelineOptions } from './default-pipeline';\nexport { PackageRules, ModuleRules } from './dependency-rules';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA8C;AAArC,kHAAA,OAAO,OAAO;AACvB,iDAAoD;AAA3C,wHAAA,OAAO,OAAU;AAC1B,qCAAmE;AAAtC,6GAAA,kBAAkB,OAAA;AAC/C,uCAAgD;AAAvC,oHAAA,OAAO,OAAW;AAC3B,uDAA6E;AAApE,gIAAA,OAAO,OAAe;AAC/B,+DAAuE;AAA9D,2IAAA,OAAO,OAAsB","sourcesContent":["export { default as App } from './compat-app';\nexport { default as Addons } from './compat-addons';\nexport { default as Options, recommendedOptions } from './options';\nexport { default as V1Addon } from './v1-addon';\nexport { default as compatBuild, PipelineOptions } from './default-pipeline';\nexport { default as templateTagCodemod } from './template-tag-codemod';\nexport { PackageRules, ModuleRules } from './dependency-rules';\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EmberAppInstance } from '@embroider/core';
|
|
2
|
+
import type { Node } from 'broccoli-node-api';
|
|
3
|
+
export interface TemplateTagCodemodOptions {
|
|
4
|
+
shouldTransformPath: (outputPath: string) => boolean;
|
|
5
|
+
dryRun: boolean;
|
|
6
|
+
}
|
|
7
|
+
export default function templateTagCodemod(emberApp: EmberAppInstance, { shouldTransformPath, dryRun }?: {
|
|
8
|
+
shouldTransformPath?: ((outputPath: string) => boolean) | undefined;
|
|
9
|
+
dryRun?: boolean | undefined;
|
|
10
|
+
}): Node;
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = templateTagCodemod;
|
|
7
|
+
const default_pipeline_1 = __importDefault(require("./default-pipeline"));
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const broccoli_plugin_1 = __importDefault(require("broccoli-plugin"));
|
|
11
|
+
const core_1 = require("@babel/core");
|
|
12
|
+
const core_2 = require("@embroider/core");
|
|
13
|
+
const babel_import_util_1 = require("babel-import-util");
|
|
14
|
+
const resolver_transform_1 = __importDefault(require("./resolver-transform"));
|
|
15
|
+
const child_process_1 = require("child_process");
|
|
16
|
+
const core_3 = require("@embroider/core");
|
|
17
|
+
function templateTagCodemod(emberApp, { shouldTransformPath = (() => true), dryRun = false } = {}) {
|
|
18
|
+
return new TemplateTagCodemodPlugin([
|
|
19
|
+
(0, default_pipeline_1.default)(emberApp, undefined, {
|
|
20
|
+
staticAddonTrees: true,
|
|
21
|
+
staticAddonTestSupportTrees: true,
|
|
22
|
+
staticComponents: true,
|
|
23
|
+
staticHelpers: true,
|
|
24
|
+
staticModifiers: true,
|
|
25
|
+
staticEmberSource: true,
|
|
26
|
+
amdCompatibility: {
|
|
27
|
+
es: [],
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
], { shouldTransformPath, dryRun });
|
|
31
|
+
}
|
|
32
|
+
class TemplateTagCodemodPlugin extends broccoli_plugin_1.default {
|
|
33
|
+
constructor(inputNodes, options) {
|
|
34
|
+
super(inputNodes, {
|
|
35
|
+
name: 'TemplateTagCodemodPlugin',
|
|
36
|
+
});
|
|
37
|
+
this.options = options;
|
|
38
|
+
}
|
|
39
|
+
async build() {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
function* walkSync(dir) {
|
|
42
|
+
const files = (0, fs_1.readdirSync)(dir);
|
|
43
|
+
for (const file of files) {
|
|
44
|
+
const pathToFile = (0, path_1.join)(dir, file);
|
|
45
|
+
const isDirectory = (0, fs_1.statSync)(pathToFile).isDirectory();
|
|
46
|
+
if (isDirectory) {
|
|
47
|
+
yield* walkSync(pathToFile);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
yield pathToFile;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
this.inputPaths[0];
|
|
55
|
+
const tmp_path = (0, fs_1.readFileSync)(this.inputPaths[0] + '/.stage2-output').toLocaleString();
|
|
56
|
+
const compatPattern = /#embroider_compat\/(?<type>[^\/]+)\/(?<rest>.*)/;
|
|
57
|
+
const resolver = new core_2.ResolverLoader(process.cwd()).resolver;
|
|
58
|
+
const hbs_file_test = /[\\/]rewritten-app[\\/]components[\\/].*\.hbs$/;
|
|
59
|
+
// locate ember-source for the host app so we know which version to insert builtIns for
|
|
60
|
+
const emberSourceEntrypoint = require.resolve('ember-source', { paths: [process.cwd()] });
|
|
61
|
+
const emberVersion = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(emberSourceEntrypoint, '../../package.json')).toString()).version;
|
|
62
|
+
for await (const current_file of walkSync(tmp_path)) {
|
|
63
|
+
if (hbs_file_test.test(current_file) && this.options.shouldTransformPath(current_file)) {
|
|
64
|
+
const template_file_src = (0, fs_1.readFileSync)(current_file).toLocaleString();
|
|
65
|
+
const ember_template_compiler = resolver.nodeResolve('ember-source/vendor/ember/ember-template-compiler', (0, path_1.resolve)((0, core_3.locateEmbroiderWorkingDir)(process.cwd()), 'rewritten-app', 'package.json'));
|
|
66
|
+
if (ember_template_compiler.type === 'not_found') {
|
|
67
|
+
throw 'This will not ever be true';
|
|
68
|
+
}
|
|
69
|
+
const embroider_compat_path = require.resolve('@embroider/compat', { paths: [process.cwd()] });
|
|
70
|
+
const babel_plugin_ember_template_compilation = require.resolve('babel-plugin-ember-template-compilation', {
|
|
71
|
+
paths: [embroider_compat_path],
|
|
72
|
+
});
|
|
73
|
+
const babel_plugin_syntax_decorators = require.resolve('@babel/plugin-syntax-decorators', {
|
|
74
|
+
paths: [embroider_compat_path],
|
|
75
|
+
});
|
|
76
|
+
let src = (_b = (_a = (0, core_1.transformSync)((0, core_2.hbsToJS)(template_file_src), {
|
|
77
|
+
plugins: [
|
|
78
|
+
[
|
|
79
|
+
babel_plugin_ember_template_compilation,
|
|
80
|
+
{
|
|
81
|
+
compilerPath: ember_template_compiler.filename,
|
|
82
|
+
transforms: [(0, resolver_transform_1.default)({ appRoot: process.cwd(), emberVersion: emberVersion })],
|
|
83
|
+
targetFormat: 'hbs',
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
],
|
|
87
|
+
})) === null || _a === void 0 ? void 0 : _a.code) !== null && _b !== void 0 ? _b : '';
|
|
88
|
+
const import_bucket = [];
|
|
89
|
+
let transformed_template_value = '';
|
|
90
|
+
(0, core_1.transformSync)(src, {
|
|
91
|
+
plugins: [
|
|
92
|
+
function template_tag_extractor() {
|
|
93
|
+
return {
|
|
94
|
+
visitor: {
|
|
95
|
+
ImportDeclaration(import_declaration) {
|
|
96
|
+
const extractor = import_declaration.node.source.value.match(compatPattern);
|
|
97
|
+
if (extractor) {
|
|
98
|
+
const result = resolver.nodeResolve(extractor[0], current_file);
|
|
99
|
+
if (result.type === 'real') {
|
|
100
|
+
// find package
|
|
101
|
+
const owner_package = resolver.packageCache.ownerOfFile(result.filename);
|
|
102
|
+
// change import to real one
|
|
103
|
+
import_declaration.node.source.value =
|
|
104
|
+
owner_package.name + '/' + extractor[1] + '/' + extractor[2];
|
|
105
|
+
import_bucket.push(import_declaration);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else if (import_declaration.node.source.value.indexOf('@ember/template-compilation') === -1) {
|
|
109
|
+
import_bucket.push(import_declaration);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
CallExpression(path) {
|
|
113
|
+
// reverse of hbs to js
|
|
114
|
+
// extract the template string to put into template tag in backing class
|
|
115
|
+
if ('name' in path.node.callee &&
|
|
116
|
+
path.node.callee.name === 'precompileTemplate' &&
|
|
117
|
+
path.node.arguments &&
|
|
118
|
+
'value' in path.node.arguments[0]) {
|
|
119
|
+
transformed_template_value = `<template>\n\t${path.node.arguments[0].value}\n</template>`;
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
});
|
|
127
|
+
//find backing class
|
|
128
|
+
const backing_class_resolution = resolver.nodeResolve('#embroider_compat/' + (0, path_1.relative)(tmp_path, current_file).replace(/[\\]/g, '/').slice(0, -4), tmp_path);
|
|
129
|
+
const backing_class_filename = 'filename' in backing_class_resolution ? backing_class_resolution.filename : '';
|
|
130
|
+
const backing_class_src = (0, fs_1.readFileSync)(backing_class_filename).toString();
|
|
131
|
+
const magic_string = '__MAGIC_STRING_FOR_TEMPLATE_TAG_REPLACE__';
|
|
132
|
+
const is_template_only = backing_class_src.indexOf("import templateOnlyComponent from '@ember/component/template-only';") !== -1;
|
|
133
|
+
src = (0, core_1.transformSync)(backing_class_src, {
|
|
134
|
+
plugins: [
|
|
135
|
+
[babel_plugin_syntax_decorators, { decoratorsBeforeExport: true }],
|
|
136
|
+
function glimmer_syntax_creator(babel) {
|
|
137
|
+
return {
|
|
138
|
+
name: 'test',
|
|
139
|
+
visitor: {
|
|
140
|
+
Program: {
|
|
141
|
+
enter(path) {
|
|
142
|
+
var _a;
|
|
143
|
+
// Always instantiate the ImportUtil instance at the Program scope
|
|
144
|
+
const importUtil = new babel_import_util_1.ImportUtil(babel.types, path);
|
|
145
|
+
const first_node = path.get('body')[0];
|
|
146
|
+
if (first_node &&
|
|
147
|
+
first_node.node &&
|
|
148
|
+
first_node.node.leadingComments &&
|
|
149
|
+
((_a = first_node.node.leadingComments[0]) === null || _a === void 0 ? void 0 : _a.value.includes('__COLOCATED_TEMPLATE__'))) {
|
|
150
|
+
//remove magic comment
|
|
151
|
+
first_node.node.leadingComments.splice(0, 1);
|
|
152
|
+
}
|
|
153
|
+
for (const template_import of import_bucket) {
|
|
154
|
+
for (let i = 0, len = template_import.node.specifiers.length; i < len; ++i) {
|
|
155
|
+
const specifier = template_import.node.specifiers[i];
|
|
156
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
157
|
+
importUtil.import(path, template_import.node.source.value, 'default', specifier.local.name);
|
|
158
|
+
}
|
|
159
|
+
else if (specifier.type === 'ImportSpecifier') {
|
|
160
|
+
importUtil.import(path, template_import.node.source.value, specifier.local.name);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
ImportDeclaration(import_declaration) {
|
|
167
|
+
if (import_declaration.node.source.value.indexOf('@ember/component/template-only') !== -1) {
|
|
168
|
+
import_declaration.remove();
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
ExportDefaultDeclaration(path) {
|
|
172
|
+
path.traverse({
|
|
173
|
+
ClassBody(path) {
|
|
174
|
+
const classbody_nodes = path.get('body');
|
|
175
|
+
//add magic string to be replaces with the contents of the template tag
|
|
176
|
+
classbody_nodes[classbody_nodes.length - 1].addComment('trailing', magic_string, false);
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
}).code.replace(`/*${magic_string}*/`, transformed_template_value);
|
|
185
|
+
if (is_template_only) {
|
|
186
|
+
// because we can't inject a comment as the default export
|
|
187
|
+
// we replace the known exported string
|
|
188
|
+
src = src.replace('templateOnlyComponent()', transformed_template_value);
|
|
189
|
+
}
|
|
190
|
+
const dryRun = this.options.dryRun ? '--dry-run' : '';
|
|
191
|
+
// work out original file path in app tree
|
|
192
|
+
const app_relative_path = (0, path_1.join)('app', (0, path_1.relative)(tmp_path, current_file));
|
|
193
|
+
const new_file_path = app_relative_path.slice(0, -4) + '.gjs';
|
|
194
|
+
// write glimmer file out
|
|
195
|
+
if (this.options.dryRun) {
|
|
196
|
+
console.log('Write new file', new_file_path, src);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(process.cwd(), new_file_path), src, { flag: 'wx+' });
|
|
200
|
+
}
|
|
201
|
+
// git rm old files (js/ts if exists + hbs)
|
|
202
|
+
let rm_hbs = await execute(`git rm ${app_relative_path} ${dryRun}`, {
|
|
203
|
+
pwd: process.cwd(),
|
|
204
|
+
});
|
|
205
|
+
console.log(rm_hbs.output);
|
|
206
|
+
if (!is_template_only) {
|
|
207
|
+
// remove backing class only if it's not a template only component
|
|
208
|
+
// resolve repative path to rewritten-app
|
|
209
|
+
const app_relative_path = (0, path_1.join)('app', (0, path_1.relative)(tmp_path, backing_class_filename));
|
|
210
|
+
let rm_js = await execute(`git rm ${app_relative_path} ${dryRun}`, {
|
|
211
|
+
pwd: process.cwd(),
|
|
212
|
+
});
|
|
213
|
+
console.log(rm_js.output);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async function execute(shellCommand, opts) {
|
|
220
|
+
let env;
|
|
221
|
+
if (opts === null || opts === void 0 ? void 0 : opts.env) {
|
|
222
|
+
env = { ...process.env, ...opts.env };
|
|
223
|
+
}
|
|
224
|
+
let child = (0, child_process_1.spawn)(shellCommand, {
|
|
225
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
226
|
+
cwd: opts === null || opts === void 0 ? void 0 : opts.pwd,
|
|
227
|
+
shell: true,
|
|
228
|
+
env,
|
|
229
|
+
});
|
|
230
|
+
let stderrBuffer = [];
|
|
231
|
+
let stdoutBuffer = [];
|
|
232
|
+
let combinedBuffer = [];
|
|
233
|
+
child.stderr.on('data', data => {
|
|
234
|
+
stderrBuffer.push(data);
|
|
235
|
+
combinedBuffer.push(data);
|
|
236
|
+
});
|
|
237
|
+
child.stdout.on('data', data => {
|
|
238
|
+
stdoutBuffer.push(data);
|
|
239
|
+
combinedBuffer.push(data);
|
|
240
|
+
});
|
|
241
|
+
return new Promise(resolve => {
|
|
242
|
+
child.on('close', (exitCode) => {
|
|
243
|
+
resolve({
|
|
244
|
+
exitCode,
|
|
245
|
+
get stdout() {
|
|
246
|
+
return stdoutBuffer.join('');
|
|
247
|
+
},
|
|
248
|
+
get stderr() {
|
|
249
|
+
return stderrBuffer.join('');
|
|
250
|
+
},
|
|
251
|
+
get output() {
|
|
252
|
+
return combinedBuffer.join('');
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=template-tag-codemod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-tag-codemod.js","sourceRoot":"","sources":["template-tag-codemod.ts"],"names":[],"mappings":";;;;;AAoBA,qCAoBC;AAxCD,0EAA4D;AAG5D,+BAA+C;AAG/C,2BAAwE;AACxE,sEAAqC;AACrC,sCAA4C;AAC5C,0CAA0D;AAC1D,yDAA+C;AAC/C,8EAAqD;AACrD,iDAAsC;AACtC,0CAA4D;AAO5D,SAAwB,kBAAkB,CACxC,QAA0B,EAC1B,EAAE,mBAAmB,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAqD,EAAE,MAAM,GAAG,KAAK,KAAK,EAAE;IAE/G,OAAO,IAAI,wBAAwB,CACjC;QACE,IAAA,0BAAW,EAAC,QAAQ,EAAE,SAAS,EAAE;YAC/B,gBAAgB,EAAE,IAAI;YACtB,2BAA2B,EAAE,IAAI;YACjC,gBAAgB,EAAE,IAAI;YACtB,aAAa,EAAE,IAAI;YACnB,eAAe,EAAE,IAAI;YACrB,iBAAiB,EAAE,IAAI;YACvB,gBAAgB,EAAE;gBAChB,EAAE,EAAE,EAAE;aACP;SACF,CAAC;KACH,EACD,EAAE,mBAAmB,EAAE,MAAM,EAAE,CAChC,C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,MAAM;oBACR,OAAO,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACjC,CAAC;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { default as compatBuild } from './default-pipeline';\nimport type { EmberAppInstance } from '@embroider/core';\nimport type { Node, InputNode } from 'broccoli-node-api';\nimport { join, relative, resolve } from 'path';\nimport type { types as t } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport { statSync, readdirSync, readFileSync, writeFileSync } from 'fs';\nimport Plugin from 'broccoli-plugin';\nimport { transformSync } from '@babel/core';\nimport { hbsToJS, ResolverLoader } from '@embroider/core';\nimport { ImportUtil } from 'babel-import-util';\nimport ResolverTransform from './resolver-transform';\nimport { spawn } from 'child_process';\nimport { locateEmbroiderWorkingDir } from '@embroider/core';\n\nexport interface TemplateTagCodemodOptions {\n shouldTransformPath: (outputPath: string) => boolean;\n dryRun: boolean;\n}\n\nexport default function templateTagCodemod(\n emberApp: EmberAppInstance,\n { shouldTransformPath = (() => true) as TemplateTagCodemodOptions['shouldTransformPath'], dryRun = false } = {}\n): Node {\n return new TemplateTagCodemodPlugin(\n [\n compatBuild(emberApp, undefined, {\n staticAddonTrees: true,\n staticAddonTestSupportTrees: true,\n staticComponents: true,\n staticHelpers: true,\n staticModifiers: true,\n staticEmberSource: true,\n amdCompatibility: {\n es: [],\n },\n }),\n ],\n { shouldTransformPath, dryRun }\n );\n}\nclass TemplateTagCodemodPlugin extends Plugin {\n constructor(inputNodes: InputNode[], readonly options: TemplateTagCodemodOptions) {\n super(inputNodes, {\n name: 'TemplateTagCodemodPlugin',\n });\n }\n async build() {\n function* walkSync(dir: string): Generator<string> {\n const files = readdirSync(dir);\n\n for (const file of files) {\n const pathToFile = join(dir, file);\n const isDirectory = statSync(pathToFile).isDirectory();\n if (isDirectory) {\n yield* walkSync(pathToFile);\n } else {\n yield pathToFile;\n }\n }\n }\n this.inputPaths[0];\n const tmp_path = readFileSync(this.inputPaths[0] + '/.stage2-output').toLocaleString();\n const compatPattern = /#embroider_compat\\/(?<type>[^\\/]+)\\/(?<rest>.*)/;\n const resolver = new ResolverLoader(process.cwd()).resolver;\n const hbs_file_test = /[\\\\/]rewritten-app[\\\\/]components[\\\\/].*\\.hbs$/;\n // locate ember-source for the host app so we know which version to insert builtIns for\n const emberSourceEntrypoint = require.resolve('ember-source', { paths: [process.cwd()] });\n const emberVersion = JSON.parse(readFileSync(join(emberSourceEntrypoint, '../../package.json')).toString()).version;\n\n for await (const current_file of walkSync(tmp_path)) {\n if (hbs_file_test.test(current_file) && this.options.shouldTransformPath(current_file)) {\n const template_file_src = readFileSync(current_file).toLocaleString();\n const ember_template_compiler = resolver.nodeResolve(\n 'ember-source/vendor/ember/ember-template-compiler',\n resolve(locateEmbroiderWorkingDir(process.cwd()), 'rewritten-app', 'package.json')\n );\n if (ember_template_compiler.type === 'not_found') {\n throw 'This will not ever be true';\n }\n\n const embroider_compat_path = require.resolve('@embroider/compat', { paths: [process.cwd()] });\n const babel_plugin_ember_template_compilation = require.resolve('babel-plugin-ember-template-compilation', {\n paths: [embroider_compat_path],\n });\n const babel_plugin_syntax_decorators = require.resolve('@babel/plugin-syntax-decorators', {\n paths: [embroider_compat_path],\n });\n let src =\n transformSync(hbsToJS(template_file_src), {\n plugins: [\n [\n babel_plugin_ember_template_compilation,\n {\n compilerPath: ember_template_compiler.filename,\n transforms: [ResolverTransform({ appRoot: process.cwd(), emberVersion: emberVersion })],\n targetFormat: 'hbs',\n },\n ],\n ],\n })?.code ?? '';\n const import_bucket: NodePath<t.ImportDeclaration>[] = [];\n let transformed_template_value = '';\n transformSync(src, {\n plugins: [\n function template_tag_extractor(): unknown {\n return {\n visitor: {\n ImportDeclaration(import_declaration: NodePath<t.ImportDeclaration>) {\n const extractor = import_declaration.node.source.value.match(compatPattern);\n if (extractor) {\n const result = resolver.nodeResolve(extractor[0], current_file);\n if (result.type === 'real') {\n // find package\n const owner_package = resolver.packageCache.ownerOfFile(result.filename);\n // change import to real one\n import_declaration.node.source.value =\n owner_package!.name + '/' + extractor[1] + '/' + extractor[2];\n import_bucket.push(import_declaration);\n }\n } else if (import_declaration.node.source.value.indexOf('@ember/template-compilation') === -1) {\n import_bucket.push(import_declaration);\n }\n },\n CallExpression(path: NodePath<t.CallExpression>) {\n // reverse of hbs to js\n // extract the template string to put into template tag in backing class\n if (\n 'name' in path.node.callee &&\n path.node.callee.name === 'precompileTemplate' &&\n path.node.arguments &&\n 'value' in path.node.arguments[0]\n ) {\n transformed_template_value = `<template>\\n\\t${path.node.arguments[0].value}\\n</template>`;\n }\n },\n },\n };\n },\n ],\n });\n\n //find backing class\n const backing_class_resolution = resolver.nodeResolve(\n '#embroider_compat/' + relative(tmp_path, current_file).replace(/[\\\\]/g, '/').slice(0, -4),\n tmp_path\n );\n\n const backing_class_filename = 'filename' in backing_class_resolution ? backing_class_resolution.filename : '';\n const backing_class_src = readFileSync(backing_class_filename).toString();\n const magic_string = '__MAGIC_STRING_FOR_TEMPLATE_TAG_REPLACE__';\n const is_template_only =\n backing_class_src.indexOf(\"import templateOnlyComponent from '@ember/component/template-only';\") !== -1;\n\n src = transformSync(backing_class_src, {\n plugins: [\n [babel_plugin_syntax_decorators, { decoratorsBeforeExport: true }],\n function glimmer_syntax_creator(babel): unknown {\n return {\n name: 'test',\n visitor: {\n Program: {\n enter(path: NodePath<t.Program>) {\n // Always instantiate the ImportUtil instance at the Program scope\n const importUtil = new ImportUtil(babel.types, path);\n const first_node = path.get('body')[0];\n if (\n first_node &&\n first_node.node &&\n first_node.node.leadingComments &&\n first_node.node.leadingComments[0]?.value.includes('__COLOCATED_TEMPLATE__')\n ) {\n //remove magic comment\n first_node.node.leadingComments.splice(0, 1);\n }\n for (const template_import of import_bucket) {\n for (let i = 0, len = template_import.node.specifiers.length; i < len; ++i) {\n const specifier = template_import.node.specifiers[i];\n if (specifier.type === 'ImportDefaultSpecifier') {\n importUtil.import(path, template_import.node.source.value, 'default', specifier.local.name);\n } else if (specifier.type === 'ImportSpecifier') {\n importUtil.import(path, template_import.node.source.value, specifier.local.name);\n }\n }\n }\n },\n },\n ImportDeclaration(import_declaration: NodePath<t.ImportDeclaration>) {\n if (import_declaration.node.source.value.indexOf('@ember/component/template-only') !== -1) {\n import_declaration.remove();\n }\n },\n ExportDefaultDeclaration(path: NodePath<t.ExportDefaultDeclaration>) {\n path.traverse({\n ClassBody(path) {\n const classbody_nodes = path.get('body');\n //add magic string to be replaces with the contents of the template tag\n classbody_nodes[classbody_nodes.length - 1].addComment('trailing', magic_string, false);\n },\n });\n },\n },\n };\n },\n ],\n })!.code!.replace(`/*${magic_string}*/`, transformed_template_value);\n if (is_template_only) {\n // because we can't inject a comment as the default export\n // we replace the known exported string\n src = src.replace('templateOnlyComponent()', transformed_template_value);\n }\n\n const dryRun = this.options.dryRun ? '--dry-run' : '';\n // work out original file path in app tree\n const app_relative_path = join('app', relative(tmp_path, current_file));\n const new_file_path = app_relative_path.slice(0, -4) + '.gjs';\n\n // write glimmer file out\n if (this.options.dryRun) {\n console.log('Write new file', new_file_path, src);\n } else {\n writeFileSync(join(process.cwd(), new_file_path), src, { flag: 'wx+' });\n }\n\n // git rm old files (js/ts if exists + hbs)\n let rm_hbs = await execute(`git rm ${app_relative_path} ${dryRun}`, {\n pwd: process.cwd(),\n });\n console.log(rm_hbs.output);\n\n if (!is_template_only) {\n // remove backing class only if it's not a template only component\n // resolve repative path to rewritten-app\n const app_relative_path = join('app', relative(tmp_path, backing_class_filename));\n let rm_js = await execute(`git rm ${app_relative_path} ${dryRun}`, {\n pwd: process.cwd(),\n });\n\n console.log(rm_js.output);\n }\n }\n }\n }\n}\n\nasync function execute(\n shellCommand: string,\n opts?: { env?: Record<string, string>; pwd?: string }\n): Promise<{\n exitCode: number;\n stderr: string;\n stdout: string;\n output: string;\n}> {\n let env: Record<string, string | undefined> | undefined;\n if (opts?.env) {\n env = { ...process.env, ...opts.env };\n }\n let child = spawn(shellCommand, {\n stdio: ['inherit', 'pipe', 'pipe'],\n cwd: opts?.pwd,\n shell: true,\n env,\n });\n let stderrBuffer: string[] = [];\n let stdoutBuffer: string[] = [];\n let combinedBuffer: string[] = [];\n child.stderr.on('data', data => {\n stderrBuffer.push(data);\n combinedBuffer.push(data);\n });\n child.stdout.on('data', data => {\n stdoutBuffer.push(data);\n combinedBuffer.push(data);\n });\n return new Promise(resolve => {\n child.on('close', (exitCode: number) => {\n resolve({\n exitCode,\n get stdout() {\n return stdoutBuffer.join('');\n },\n get stderr() {\n return stderrBuffer.join('');\n },\n get output() {\n return combinedBuffer.join('');\n },\n });\n });\n });\n}\n"]}
|