Skip to content

Commit 596a86f

Browse files
Better platform support; improved tree style
1 parent 6cff307 commit 596a86f

17 files changed

+515
-378
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ A basic tool for debugging syntax trees by visualizing them. This module
88
exports two functions, one for directly printing to the console and another
99
one for storing the formatted string (without color formatting).
1010

11-
This modules supports both native consoles and the web. Be sure to use CommonJS
12-
for the native version and the ES-module for web color support.
11+
This modules supports both native consoles and the web. This library detects
12+
if it is run in the browser or Node.
1313

1414
## Example
1515

img/java-tree.png

22.9 KB
Loading

package-lock.json

+2-42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@colin_t/lezer-tree-visualizer",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Visualizes a lezer tree to view it in a console",
55
"main": "dist/index.cjs",
66
"exports": {
@@ -32,7 +32,6 @@
3232
},
3333
"homepage": "https://github.com/ColinTimBarndt/lezer-tree-visualizer#readme",
3434
"devDependencies": {
35-
"@rollup/plugin-alias": "^3.1.2",
3635
"@rollup/plugin-multi-entry": "^4.0.0",
3736
"@rollup/plugin-node-resolve": "^13.0.0",
3837
"@rollup/plugin-typescript": "^8.2.1",

rollup.config.js

+20-35
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,27 @@ import { nodeResolve } from "@rollup/plugin-node-resolve";
33
import dts from "rollup-plugin-dts";
44
import { terser } from "rollup-plugin-terser";
55
import npmpkg from "./package.json";
6-
import alias from '@rollup/plugin-alias';
7-
import path from 'path';
86

97
export default [
10-
config("os", "index.cjs", "cjs", "src/index.ts"),
11-
config("web", "index.js", "es", "src/index.ts"),
8+
{
9+
input: "src/index.ts",
10+
output: [
11+
{
12+
file: "dist/index.js",
13+
format: "es",
14+
},
15+
{
16+
file: "dist/index.cjs",
17+
format: "cjs",
18+
}
19+
],
20+
external: Object.keys(npmpkg.dependencies),
21+
plugins: [
22+
nodeResolve(),
23+
typescript(),
24+
terser(),
25+
],
26+
},
1227
{
1328
input: "src/index.ts",
1429
output: {
@@ -19,34 +34,4 @@ export default [
1934
dts(),
2035
],
2136
},
22-
];
23-
24-
function config(platform, file, format, inputFiles) {
25-
return {
26-
input: inputFiles,
27-
output: {
28-
file: "dist/" + file,
29-
format: format,
30-
},
31-
external: Object.keys(npmpkg.dependencies),
32-
plugins: [
33-
nodeResolve(),
34-
typescript(),
35-
target(platform),
36-
],
37-
};
38-
}
39-
40-
function target(t) {
41-
return alias({
42-
entries: [
43-
{
44-
find: /\/platform-color$/,
45-
customResolver(relative, origin) {
46-
if (/node_modules/.test(origin)) return;
47-
return path.resolve(__dirname, "src", t + "-color.ts");
48-
}
49-
}
50-
]
51-
});
52-
}
37+
];

rollup.config.test.js

+28-52
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,37 @@
11
import typescript from "@rollup/plugin-typescript";
22
import nodeResolve from "@rollup/plugin-node-resolve";
33
import { string } from "rollup-plugin-string";
4-
import { readdir } from "fs";
54
import multi from '@rollup/plugin-multi-entry';
6-
import alias from '@rollup/plugin-alias';
75

8-
import path from "path";
6+
const baseConfig = {
7+
input: "tests/**/*.test.ts",
8+
inlineDynamicImports: true,
9+
plugins: [
10+
string({
11+
include: ["**/*.java"]
12+
}),
13+
typescript(),
14+
nodeResolve(),
15+
multi(),
16+
],
17+
};
918

10-
export default new Promise((resolve, reject) => {
11-
readdir("tests", {}, (err, files) => {
12-
const inputFiles = files
13-
.filter(f => f.endsWith(".test.ts"))
14-
.map(f => `tests/${f}`);
15-
if (err) return reject(err);
16-
resolve([
17-
config("os", "tests.cjs", "cjs", inputFiles),
18-
config("web", "tests.js", "es", inputFiles),
19-
]);
20-
});
21-
});
22-
23-
function config(platform, file, format, inputFiles) {
24-
return {
25-
input: inputFiles,
19+
export default [
20+
{
21+
...baseConfig,
2622
output: {
27-
file: "tests/dist/" + file,
28-
format: format,
23+
file: "tests/dist/tests.cjs",
24+
format: "cjs",
2925
sourcemap: true,
3026
},
31-
inlineDynamicImports: true,
32-
external: platform === "os"
33-
? [
34-
/node_modules/,
35-
]
36-
: [],
37-
plugins: [
38-
string({
39-
include: ["**/*.java"]
40-
}),
41-
typescript(),
42-
nodeResolve(),
43-
multi(),
44-
target(platform),
45-
],
46-
};
47-
}
48-
49-
function target(t) {
50-
return alias({
51-
entries: [
52-
{
53-
find: /\/platform-color$/,
54-
customResolver(relative, origin) {
55-
if (/\/node_modules\//.test(origin)) return;
56-
return path.resolve(__dirname, "src", t + "-color.ts");
57-
}
58-
}
59-
]
60-
});
61-
}
27+
external: /node_modules/,
28+
},
29+
{
30+
...baseConfig,
31+
output: {
32+
file: "tests/dist/tests.js",
33+
format: "es",
34+
sourcemap: true,
35+
}
36+
}
37+
];

0 commit comments

Comments
 (0)