Skip to content

Commit 4a4b27f

Browse files
committed
It’s working but needs some polish! #4194 and #4195
1 parent e9a1666 commit 4a4b27f

11 files changed

Lines changed: 87 additions & 19 deletions

package-lock.json

Lines changed: 27 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
"dependencies": {
136136
"@11ty/dependency-tree": "^4.0.1",
137137
"@11ty/dependency-tree-esm": "^2.0.3",
138+
"@11ty/dependency-tree-typescript": "^1.0.0",
138139
"@11ty/eleventy-dev-server": "^3.0.0-alpha.6",
139140
"@11ty/eleventy-plugin-bundle": "^3.0.7",
140141
"@11ty/eleventy-utils": "^2.0.7",

src/Data/TemplateData.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,21 @@ class TemplateData {
173173
globSuffixesWithLeadingDot.add(`${suffix.slice(1)}.mjs`);
174174
globSuffixesWithLeadingDot.add(`${suffix.slice(1)}.cjs`);
175175
globSuffixesWithLeadingDot.add(`${suffix.slice(1)}.js`);
176+
177+
// TODO Node 22+ only
178+
globSuffixesWithLeadingDot.add(`${suffix.slice(1)}.mts`);
179+
globSuffixesWithLeadingDot.add(`${suffix.slice(1)}.cts`);
180+
globSuffixesWithLeadingDot.add(`${suffix.slice(1)}.ts`);
176181
} else {
177182
// "suffix.js" without leading dot
178183
globSuffixesWithoutLeadingDot.add(`${suffix || ""}.mjs`);
179184
globSuffixesWithoutLeadingDot.add(`${suffix || ""}.cjs`);
180185
globSuffixesWithoutLeadingDot.add(`${suffix || ""}.js`);
186+
187+
// TODO Node 22+ only
188+
globSuffixesWithoutLeadingDot.add(`${suffix || ""}.mts`);
189+
globSuffixesWithoutLeadingDot.add(`${suffix || ""}.cts`);
190+
globSuffixesWithoutLeadingDot.add(`${suffix || ""}.ts`);
181191
}
182192
}
183193
}
@@ -209,7 +219,7 @@ class TemplateData {
209219
if (suffix) {
210220
// TODO this check is purely for backwards compat and I kinda feel like it shouldn’t be here
211221
// paths.push(`${this.inputDir}/**/*${suffix || ""}.cjs`); // Same as above
212-
paths.push(`${this.inputDir}**/*${suffix || ""}.js`);
222+
paths.push(`${this.inputDir}**/*${suffix || ""}.js`); // TODO typescript?
213223
}
214224
}
215225

src/EleventyExtensionMap.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ class EleventyExtensionMap {
263263
"11ty.js": { key: "11ty.js", extension: "11ty.js" },
264264
"11ty.cjs": { key: "11ty.js", extension: "11ty.cjs" },
265265
"11ty.mjs": { key: "11ty.js", extension: "11ty.mjs" },
266+
// TODO node 22+ only
267+
"11ty.ts": { key: "11ty.js", extension: "11ty.ts" },
268+
"11ty.cts": { key: "11ty.js", extension: "11ty.cts" },
269+
"11ty.mts": { key: "11ty.js", extension: "11ty.mts" },
266270
};
267271

268272
if ("extensionMap" in this.config) {

src/Plugins/RenderPlugin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ async function compile(content, templateLang, options = {}) {
5151
if (
5252
tr.engine.name === "11ty.js" ||
5353
tr.engine.name === "11ty.cjs" ||
54-
tr.engine.name === "11ty.mjs"
54+
tr.engine.name === "11ty.mjs" ||
55+
// TODO Node 22+
56+
tr.engine.name === "11ty.ts" ||
57+
tr.engine.name === "11ty.cts" ||
58+
tr.engine.name === "11ty.mts"
5559
) {
5660
throw new Error(
5761
"11ty.js is not yet supported as a template engine for `renderTemplate`. Use `renderFile` instead!",

src/TemplateConfig.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class TemplateConfig {
7878
"eleventy.config.js",
7979
"eleventy.config.mjs",
8080
"eleventy.config.cjs",
81+
// TODO node 22+ only
82+
"eleventy.config.ts",
83+
"eleventy.config.mts",
84+
"eleventy.config.cts",
8185
];
8286
}
8387

src/Util/JavaScriptDependencies.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import dependencyTree from "@11ty/dependency-tree";
22
import { find, findGraph, mergeGraphs } from "@11ty/dependency-tree-esm";
3+
import {
4+
find as findTypeScript,
5+
findGraph as findTypeScriptGraph,
6+
} from "@11ty/dependency-tree-typescript";
37
import { TemplatePath } from "@11ty/eleventy-utils";
48
import { DepGraph } from "dependency-graph";
59

@@ -11,12 +15,33 @@ class JavaScriptDependencies {
1115
return `A problem was encountered looking for JavaScript dependencies in ${type} file: ${file}. This only affects --watch and --serve behavior and does not affect your build.`;
1216
}
1317

18+
static getFlavor(filePath, isProjectUsingEsm) {
19+
if (
20+
(isProjectUsingEsm && (filePath.endsWith(".js") || filePath.endsWith(".ts"))) ||
21+
filePath.endsWith(".mjs") ||
22+
filePath.endsWith(".mts")
23+
) {
24+
return "esm";
25+
}
26+
if (
27+
(!isProjectUsingEsm && (filePath.endsWith(".js") || filePath.endsWith(".ts"))) ||
28+
filePath.endsWith(".cjs") ||
29+
filePath.endsWith(".cts")
30+
) {
31+
return "cjs";
32+
}
33+
}
34+
35+
static isTypeScript(filePath) {
36+
return filePath.endsWith(".ts") || filePath.endsWith(".cts") || filePath.endsWith(".mts");
37+
}
38+
1439
static async getCommonJsDependencies(inputFiles, isProjectUsingEsm) {
1540
let depSet = new Set();
1641

1742
// TODO does this need to work with aliasing? what other JS extensions will have deps?
1843
let commonJsFiles = inputFiles.filter(
19-
(file) => (!isProjectUsingEsm && file.endsWith(".js")) || file.endsWith(".cjs"),
44+
(file) => this.getFlavor(file, isProjectUsingEsm) === "cjs",
2045
);
2146

2247
for (let file of commonJsFiles) {
@@ -42,12 +67,10 @@ class JavaScriptDependencies {
4267
static async getEsmDependencies(inputFiles, isProjectUsingEsm) {
4368
let depSet = new Set();
4469

45-
let esmFiles = inputFiles.filter(
46-
(file) => (isProjectUsingEsm && file.endsWith(".js")) || file.endsWith(".mjs"),
47-
);
70+
let esmFiles = inputFiles.filter((file) => this.getFlavor(file, isProjectUsingEsm) === "esm");
4871
for (let file of esmFiles) {
4972
try {
50-
let modules = await find(file);
73+
let modules = await (this.isTypeScript(file) ? findTypeScript : find)(file);
5174
for (let dep of modules) {
5275
depSet.add(dep);
5376
}
@@ -67,12 +90,10 @@ class JavaScriptDependencies {
6790

6891
static async getEsmGraph(inputFiles, isProjectUsingEsm) {
6992
let rootGraph = new DepGraph();
70-
let esmFiles = inputFiles.filter(
71-
(file) => (isProjectUsingEsm && file.endsWith(".js")) || file.endsWith(".mjs"),
72-
);
93+
let esmFiles = inputFiles.filter((file) => this.getFlavor(file, isProjectUsingEsm) === "esm");
7394
for (let file of esmFiles) {
7495
try {
75-
let graph = await findGraph(file);
96+
let graph = await (this.isTypeScript(file) ? findTypeScriptGraph : findGraph)(file);
7697

7798
mergeGraphs(rootGraph, graph);
7899
} catch (e) {

test/EleventyFilesTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ test("Glob Watcher Files with Config Passthroughs (no template formats)", async
431431
evf.init();
432432

433433
t.deepEqual(await evf.getGlobWatcherTemplateDataFiles(), [
434-
"./test/stubs/**/*.{json,11tydata.mjs,11tydata.cjs,11tydata.js}",
434+
"./test/stubs/**/*.{json,11tydata.mjs,11tydata.cjs,11tydata.js,11tydata.mts,11tydata.cts,11tydata.ts}",
435435
]);
436436
});
437437

test/EleventyTest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ test("Eleventy file watching", async (t) => {
129129
"./.gitignore",
130130
"./.eleventyignore",
131131
"./test/stubs/.eleventyignore",
132-
"./test/stubs/**/*.{json,11tydata.mjs,11tydata.cjs,11tydata.js}",
132+
"./test/stubs/**/*.{json,11tydata.mjs,11tydata.cjs,11tydata.js,11tydata.mts,11tydata.cts,11tydata.ts}",
133133
"./test/stubs/deps/dep1.cjs",
134134
"./test/stubs/deps/dep2.cjs",
135135
]);
@@ -180,7 +180,7 @@ test("Eleventy file watching (no JS dependencies)", async (t) => {
180180
"./.gitignore",
181181
"./.eleventyignore",
182182
"./test/stubs/.eleventyignore",
183-
"./test/stubs/**/*.{json,11tydata.mjs,11tydata.cjs,11tydata.js}",
183+
"./test/stubs/**/*.{json,11tydata.mjs,11tydata.cjs,11tydata.js,11tydata.mts,11tydata.cts,11tydata.ts}",
184184
]);
185185

186186
t.true(ignores.includes("node_modules/**"));

test/TemplateDataTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ test("getTemplateDataFileGlob", async (t) => {
693693
let tw = new TemplateData(eleventyConfig);
694694

695695
t.deepEqual(await tw.getTemplateDataFileGlob(), [
696-
"./test/stubs/**/*.{json,11tydata.mjs,11tydata.cjs,11tydata.js}",
696+
"./test/stubs/**/*.{json,11tydata.mjs,11tydata.cjs,11tydata.js,11tydata.mts,11tydata.cts,11tydata.ts}",
697697
]);
698698
});
699699

0 commit comments

Comments
 (0)