Skip to content

Commit cf4a2d2

Browse files
author
Denis Bardadym
committed
Cleanup typescript configs a little
1 parent 882681b commit cf4a2d2

16 files changed

+211
-184
lines changed

bin/cli.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/usr/bin/env node
22

3-
import { promises as fs } from "fs";
4-
import path from "path";
3+
import { promises as fs } from "node:fs";
4+
import path from "node:path";
55

66
import opn from "open";
77
import yargs from "yargs";
88
import { hideBin } from "yargs/helpers";
99

10-
import { renderTemplate } from "../plugin/render-template";
11-
import TEMPLATE, { TemplateType } from "../plugin/template-types";
12-
import { warn } from "../plugin/warn";
13-
import { version } from "../plugin/version";
14-
import { ModuleMeta, ModulePart, ModuleTree, ModuleUID, VisualizerData } from "../shared/types";
10+
import { renderTemplate } from "../plugin/render-template.js";
11+
import TEMPLATE, { TemplateType } from "../plugin/template-types.js";
12+
import { warn } from "../plugin/warn.js";
13+
import { version } from "../plugin/version.js";
14+
import { ModuleMeta, ModulePart, ModuleTree, ModuleUID, VisualizerData } from "../shared/types.js";
1515

1616
const argv = yargs(hideBin(process.argv))
1717
.option("filename", {

plugin/compress.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as zlib from "zlib";
2-
import { promisify } from "util";
1+
import * as zlib from "node:zlib";
2+
import { promisify } from "node:util";
33

44
const gzip = promisify(zlib.gzip);
55
const brotliCompress = promisify(zlib.brotliCompress);

plugin/data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GetModuleInfo } from "rollup";
2-
import { isModuleTree, ModuleLengths, ModuleTree, ModuleTreeLeaf } from "../shared/types";
3-
import { ModuleMapper } from "./module-mapper";
2+
import { isModuleTree, ModuleLengths, ModuleTree, ModuleTreeLeaf } from "../shared/types.js";
3+
import { ModuleMapper } from "./module-mapper.js";
44

55
interface MappedNode {
66
uid: string;

plugin/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { promises as fs } from "fs";
2-
import path from "path";
1+
import { promises as fs } from "node:fs";
2+
import path from "node:path";
33

44
import { OutputBundle, Plugin, NormalizedOutputOptions, OutputOptions } from "rollup";
55
import opn, { Options as OpenOptions } from "open";
66

7-
import { ModuleLengths, ModuleTree, ModuleTreeLeaf, VisualizerData } from "../shared/types";
8-
import { version } from "./version";
7+
import { ModuleLengths, ModuleTree, ModuleTreeLeaf, VisualizerData } from "../shared/types.js";
8+
import { version } from "./version.js";
99

10-
import { createGzipSizeGetter, createBrotliSizeGetter, SizeGetter } from "./compress";
10+
import { createGzipSizeGetter, createBrotliSizeGetter, SizeGetter } from "./compress.js";
1111

12-
import { TemplateType } from "./template-types";
13-
import { ModuleMapper, replaceHashPlaceholders } from "./module-mapper";
14-
import { addLinks, buildTree, mergeTrees } from "./data";
15-
import { getSourcemapModules } from "./sourcemap";
16-
import { renderTemplate } from "./render-template";
17-
import { createFilter, Filter } from "../shared/create-filter";
12+
import { TemplateType } from "./template-types.js";
13+
import { ModuleMapper, replaceHashPlaceholders } from "./module-mapper.js";
14+
import { addLinks, buildTree, mergeTrees } from "./data.js";
15+
import { getSourcemapModules } from "./sourcemap.js";
16+
import { renderTemplate } from "./render-template.js";
17+
import { createFilter, Filter } from "../shared/create-filter.js";
1818

1919
const WARN_SOURCEMAP_DISABLED =
2020
"rollup output configuration missing sourcemap = true. You should add output.sourcemap = true or disable sourcemap in this plugin";

plugin/module-mapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
ModuleLengths,
66
ModuleUID,
77
VisualizerData,
8-
} from "../shared/types";
9-
import * as crypto from "crypto";
8+
} from "../shared/types.js";
9+
import * as crypto from "node:crypto";
1010

1111
const HASH_PLACEHOLDER = "!{ROLLUP_VISUALIZER_HASH_PLACEHOLDER}";
1212
const HASH_PLACEHOLDER_REGEXP = new RegExp(`"${HASH_PLACEHOLDER}-(\\d+)"`, "g");

plugin/render-template.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable @typescript-eslint/require-await */
2-
import { promises as fs } from "fs";
3-
import path from "path";
4-
import { BundleId, ModuleLengths, VisualizerData } from "../shared/types";
5-
import { TemplateType } from "./template-types";
2+
import { promises as fs } from "node:fs";
3+
import path from "node:path";
4+
import { BundleId, ModuleLengths, VisualizerData } from "../shared/types.js";
5+
import { TemplateType } from "./template-types.js";
66

77
const htmlEscape = (str: string) =>
88
str
@@ -63,8 +63,8 @@ const buildHtml =
6363
(template: TemplateType) =>
6464
async ({ title, data }: RenderTemplateOptions): Promise<string> => {
6565
const [script, style] = await Promise.all([
66-
fs.readFile(path.join(__dirname, "..", "lib", `${template}.js`), "utf8"),
67-
fs.readFile(path.join(__dirname, "..", "lib", `${template}.css`), "utf8"),
66+
fs.readFile(path.join(import.meta.dirname, "..", "lib", `${template}.js`), "utf8"),
67+
fs.readFile(path.join(import.meta.dirname, "..", "lib", `${template}.css`), "utf8"),
6868
]);
6969

7070
return buildHtmlTemplate(title, script, data, style);

plugin/sourcemap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from "path";
1+
import path from "node:path";
22
import { OutputChunk } from "rollup";
33
import type { RawSourceMap } from "source-map";
44
import { SourceMapConsumer } from "source-map";

rollup.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export default HTML_TEMPLATE.map((templateType) => ({
1111
input: `./src/${templateType}/index.tsx`,
1212

1313
plugins: [
14-
typescript({ tsconfig: "./src/tsconfig.json", noEmitOnError: true }),
14+
typescript({
15+
tsconfig: "./src/tsconfig.json",
16+
noEmitOnError: false,
17+
}),
1518
resolve({ mainFields: ["module", "main"] }),
1619
commonJs({
1720
ignoreGlobal: true,

shared/create-filter.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from "vitest";
2-
import { createFilter } from "./create-filter";
2+
import { createFilter } from "./create-filter.js";
33

44
describe("createFilter", () => {
55
it("should return true when input and output is empty", () => {

src/tsconfig.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111
"isolatedModules": true,
1212
"jsx": "react-jsx",
1313
"jsxImportSource": "preact",
14-
"moduleResolution": "node",
14+
"moduleResolution": "bundler",
1515
"noEmit": true,
1616
"noFallthroughCasesInSwitch": true,
1717
"resolveJsonModule": true,
1818
"skipLibCheck": true,
1919
"strict": true,
20-
"paths": {
21-
"*": ["../node_modules/*", "./@types/*"]
22-
},
23-
"types": []
20+
21+
2422
},
2523
"include": ["./**/*", "../shared/**/*"],
2624
"exclude": ["node_modules"]

0 commit comments

Comments
 (0)