@eighty4/dank 0.0.4-1 → 0.0.4-3
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/client/client.js +1 -0
- package/lib/bin.ts +8 -11
- package/lib/build.ts +41 -70
- package/lib/build_tag.ts +3 -3
- package/lib/config.ts +372 -11
- package/lib/dank.ts +21 -150
- package/lib/define.ts +6 -4
- package/lib/developer.ts +146 -0
- package/lib/dirs.ts +83 -0
- package/lib/errors.ts +6 -0
- package/lib/esbuild.ts +19 -29
- package/lib/flags.ts +15 -121
- package/lib/html.ts +196 -112
- package/lib/http.ts +59 -43
- package/lib/public.ts +10 -10
- package/lib/{metadata.ts → registry.ts} +216 -83
- package/lib/serve.ts +118 -270
- package/lib/services.ts +8 -8
- package/lib/watch.ts +39 -0
- package/lib_js/bin.js +79 -85
- package/lib_js/build.js +63 -86
- package/lib_js/build_tag.js +20 -21
- package/lib_js/config.js +237 -18
- package/lib_js/dank.js +5 -122
- package/lib_js/define.js +8 -5
- package/lib_js/dirs.js +61 -0
- package/lib_js/errors.js +9 -0
- package/lib_js/esbuild.js +155 -167
- package/lib_js/flags.js +30 -123
- package/lib_js/html.js +280 -231
- package/lib_js/http.js +176 -195
- package/lib_js/public.js +45 -46
- package/lib_js/registry.js +260 -0
- package/lib_js/serve.js +109 -251
- package/lib_js/services.js +152 -171
- package/lib_js/watch.js +35 -0
- package/lib_types/dank.d.ts +13 -1
- package/package.json +10 -4
- package/client/esbuild.js +0 -91
- package/lib_js/metadata.js +0 -210
package/lib_js/dank.js
CHANGED
|
@@ -1,123 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (typeof c.port !== 'number') {
|
|
4
|
-
throw Error('DankConfig.port must be a number');
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
if (c.previewPort !== null && typeof c.previewPort !== 'undefined') {
|
|
8
|
-
if (typeof c.previewPort !== 'number') {
|
|
9
|
-
throw Error('DankConfig.previewPort must be a number');
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
validatePages(c.pages);
|
|
13
|
-
validateDevServices(c.services);
|
|
14
|
-
validateEsbuildConfig(c.esbuild);
|
|
15
|
-
normalizePagePaths(c.pages);
|
|
16
|
-
return c;
|
|
17
|
-
}
|
|
18
|
-
function validateEsbuildConfig(esbuild) {
|
|
19
|
-
if (esbuild?.loaders !== null && typeof esbuild?.loaders !== 'undefined') {
|
|
20
|
-
if (typeof esbuild.loaders !== 'object') {
|
|
21
|
-
throw Error('DankConfig.esbuild.loaders must be a map of extensions to esbuild loaders');
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
for (const [ext, loader] of Object.entries(esbuild.loaders)) {
|
|
25
|
-
if (typeof loader !== 'string') {
|
|
26
|
-
throw Error(`DankConfig.esbuild.loaders['${ext}'] must be a string of a loader name`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (esbuild?.plugins !== null && typeof esbuild?.plugins !== 'undefined') {
|
|
32
|
-
if (!Array.isArray(esbuild.plugins)) {
|
|
33
|
-
throw Error('DankConfig.esbuild.plugins must be an array of esbuild plugins');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (esbuild?.port !== null && typeof esbuild?.port !== 'undefined') {
|
|
37
|
-
if (typeof esbuild.port !== 'number') {
|
|
38
|
-
throw Error('DankConfig.esbuild.port must be a number');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function validatePages(pages) {
|
|
43
|
-
if (pages === null ||
|
|
44
|
-
typeof pages === 'undefined' ||
|
|
45
|
-
Object.keys(pages).length === 0) {
|
|
46
|
-
throw Error('DankConfig.pages is required');
|
|
47
|
-
}
|
|
48
|
-
for (const [urlPath, mapping] of Object.entries(pages)) {
|
|
49
|
-
if (typeof mapping === 'string' && mapping.endsWith('.html')) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (typeof mapping === 'object') {
|
|
53
|
-
validatePageMapping(urlPath, mapping);
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
throw Error(`DankConfig.pages['${urlPath}'] must configure an html file`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function validatePageMapping(urlPath, mapping) {
|
|
60
|
-
if (mapping.webpage === null ||
|
|
61
|
-
typeof mapping.webpage !== 'string' ||
|
|
62
|
-
!mapping.webpage.endsWith('.html')) {
|
|
63
|
-
throw Error(`DankConfig.pages['${urlPath}'].webpage must configure an html file`);
|
|
64
|
-
}
|
|
65
|
-
if (mapping.pattern === null || typeof mapping.pattern === 'undefined') {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (typeof mapping.pattern === 'object' &&
|
|
69
|
-
mapping.pattern.constructor.name === 'RegExp') {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
throw Error(`DankConfig.pages['${urlPath}'].pattern must be a RegExp`);
|
|
73
|
-
}
|
|
74
|
-
function validateDevServices(services) {
|
|
75
|
-
if (services === null || typeof services === 'undefined') {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (!Array.isArray(services)) {
|
|
79
|
-
throw Error(`DankConfig.services must be an array`);
|
|
80
|
-
}
|
|
81
|
-
for (let i = 0; i < services.length; i++) {
|
|
82
|
-
const s = services[i];
|
|
83
|
-
if (s.command === null || typeof s.command === 'undefined') {
|
|
84
|
-
throw Error(`DankConfig.services[${i}].command is required`);
|
|
85
|
-
}
|
|
86
|
-
else if (typeof s.command !== 'string' || s.command.length === 0) {
|
|
87
|
-
throw Error(`DankConfig.services[${i}].command must be a non-empty string`);
|
|
88
|
-
}
|
|
89
|
-
if (s.cwd !== null && typeof s.cwd !== 'undefined') {
|
|
90
|
-
if (typeof s.cwd !== 'string' || s.cwd.trim().length === 0) {
|
|
91
|
-
throw Error(`DankConfig.services[${i}].cwd must be a non-empty string`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (s.env !== null && typeof s.env !== 'undefined') {
|
|
95
|
-
if (typeof s.env !== 'object') {
|
|
96
|
-
throw Error(`DankConfig.services[${i}].env must be an env variable map`);
|
|
97
|
-
}
|
|
98
|
-
for (const [k, v] of Object.entries(s.env)) {
|
|
99
|
-
if (typeof v !== 'string') {
|
|
100
|
-
throw Error(`DankConfig.services[${i}].env[${k}] must be a string`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (s.http !== null && typeof s.http !== 'undefined') {
|
|
105
|
-
if (typeof s.http.port !== 'number') {
|
|
106
|
-
throw Error(`DankConfig.services[${i}].http.port must be a number`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function normalizePagePaths(pages) {
|
|
112
|
-
for (const [pageUrl, mapping] of Object.entries(pages)) {
|
|
113
|
-
if (typeof mapping === 'string') {
|
|
114
|
-
pages[pageUrl] = normalizePagePath(mapping);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
mapping.webpage = normalizePagePath(mapping.webpage);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function normalizePagePath(p) {
|
|
122
|
-
return p.replace(/^\.\//, '');
|
|
1
|
+
function defineConfig(config) {
|
|
2
|
+
return config;
|
|
123
3
|
}
|
|
4
|
+
export {
|
|
5
|
+
defineConfig
|
|
6
|
+
};
|
package/lib_js/define.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function createGlobalDefinitions(c) {
|
|
2
|
+
return {
|
|
3
|
+
"dank.IS_DEV": JSON.stringify(!c.flags.production),
|
|
4
|
+
"dank.IS_PROD": JSON.stringify(c.flags.production)
|
|
5
|
+
};
|
|
6
6
|
}
|
|
7
|
+
export {
|
|
8
|
+
createGlobalDefinitions
|
|
9
|
+
};
|
package/lib_js/dirs.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { realpath } from "node:fs/promises";
|
|
2
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
3
|
+
import { cwd } from "node:process";
|
|
4
|
+
async function defaultProjectDirs(projectRootAbs) {
|
|
5
|
+
if (!projectRootAbs) {
|
|
6
|
+
projectRootAbs = cwd();
|
|
7
|
+
} else if (!isAbsolute(projectRootAbs)) {
|
|
8
|
+
throw Error();
|
|
9
|
+
}
|
|
10
|
+
const projectResolved = await realpath(projectRootAbs);
|
|
11
|
+
const pages = "pages";
|
|
12
|
+
const pagesResolved = join(projectResolved, pages);
|
|
13
|
+
return Object.freeze({
|
|
14
|
+
buildRoot: "build",
|
|
15
|
+
buildDist: join("build", "dist"),
|
|
16
|
+
buildWatch: join("build", "watch"),
|
|
17
|
+
pages,
|
|
18
|
+
pagesResolved,
|
|
19
|
+
projectResolved,
|
|
20
|
+
projectRootAbs,
|
|
21
|
+
public: "public"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
class Resolver {
|
|
25
|
+
#dirs;
|
|
26
|
+
constructor(dirs) {
|
|
27
|
+
this.#dirs = dirs;
|
|
28
|
+
}
|
|
29
|
+
// cross platform safe absolute path resolution from pages dir
|
|
30
|
+
absPagesPath(...p) {
|
|
31
|
+
return join(this.#dirs.projectRootAbs, this.#dirs.pages, ...p);
|
|
32
|
+
}
|
|
33
|
+
// cross platform safe absolute path resolution from project root
|
|
34
|
+
absProjectPath(...p) {
|
|
35
|
+
return join(this.#dirs.projectRootAbs, ...p);
|
|
36
|
+
}
|
|
37
|
+
// `p` is expected to be a relative path resolvable from the project dir
|
|
38
|
+
isProjectSubpathInPagesDir(p) {
|
|
39
|
+
return resolve(join(this.#dirs.projectResolved, p)).startsWith(this.#dirs.pagesResolved);
|
|
40
|
+
}
|
|
41
|
+
// `p` is expected to be a relative path resolvable from the pages dir
|
|
42
|
+
isPagesSubpathInPagesDir(p) {
|
|
43
|
+
return this.isProjectSubpathInPagesDir(join(this.#dirs.pages, p));
|
|
44
|
+
}
|
|
45
|
+
// resolve a pages subpath from a resource within the pages directory by a relative href
|
|
46
|
+
// `from` is expected to be a pages resource fs path starting with `pages/` and ending with filename
|
|
47
|
+
// the result will be a pages subpath and will not have the pages dir prefix
|
|
48
|
+
// returns 'outofbounds' if the relative path does not resolve to a file within the pages dir
|
|
49
|
+
resolveHrefInPagesDir(from, href) {
|
|
50
|
+
const p = join(dirname(from), href);
|
|
51
|
+
if (this.isProjectSubpathInPagesDir(p)) {
|
|
52
|
+
return p;
|
|
53
|
+
} else {
|
|
54
|
+
return "outofbounds";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
Resolver,
|
|
60
|
+
defaultProjectDirs
|
|
61
|
+
};
|
package/lib_js/errors.js
ADDED
package/lib_js/esbuild.js
CHANGED
|
@@ -1,186 +1,174 @@
|
|
|
1
|
-
import { readFile } from
|
|
2
|
-
import esbuild, {} from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import esbuild, {} from "esbuild";
|
|
3
|
+
async function esbuildDevContext(r, define, entryPoints) {
|
|
4
|
+
return await esbuild.context({
|
|
5
|
+
define,
|
|
6
|
+
entryNames: "[dir]/[name]",
|
|
7
|
+
entryPoints: mapEntryPointPaths(entryPoints),
|
|
8
|
+
outdir: r.config.dirs.buildWatch,
|
|
9
|
+
...commonBuildOptions(r),
|
|
10
|
+
splitting: false,
|
|
11
|
+
write: false
|
|
12
|
+
});
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
14
|
+
async function esbuildWebpages(r, define, entryPoints) {
|
|
15
|
+
try {
|
|
16
|
+
await esbuild.build({
|
|
17
|
+
define,
|
|
18
|
+
entryNames: "[dir]/[name]-[hash]",
|
|
19
|
+
entryPoints: mapEntryPointPaths(entryPoints),
|
|
20
|
+
outdir: r.config.dirs.buildDist,
|
|
21
|
+
...commonBuildOptions(r)
|
|
22
|
+
});
|
|
23
|
+
} catch (ignore) {
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
27
|
+
async function esbuildWorkers(r, define, entryPoints) {
|
|
28
|
+
try {
|
|
29
|
+
await esbuild.build({
|
|
30
|
+
define,
|
|
31
|
+
entryNames: "[dir]/[name]-[hash]",
|
|
32
|
+
entryPoints: mapEntryPointPaths(entryPoints),
|
|
33
|
+
outdir: r.config.dirs.buildDist,
|
|
34
|
+
...commonBuildOptions(r),
|
|
35
|
+
splitting: false,
|
|
36
|
+
metafile: true,
|
|
37
|
+
write: true,
|
|
38
|
+
assetNames: "assets/[name]-[hash]"
|
|
39
|
+
});
|
|
40
|
+
} catch (ignore) {
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
45
43
|
}
|
|
46
|
-
function commonBuildOptions(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
44
|
+
function commonBuildOptions(r) {
|
|
45
|
+
const p = workersPlugin(r.buildRegistry());
|
|
46
|
+
return {
|
|
47
|
+
assetNames: "assets/[name]-[hash]",
|
|
48
|
+
bundle: true,
|
|
49
|
+
format: "esm",
|
|
50
|
+
loader: r.config.esbuild?.loaders || defaultLoaders(),
|
|
51
|
+
metafile: true,
|
|
52
|
+
minify: r.config.flags.minify,
|
|
53
|
+
platform: "browser",
|
|
54
|
+
plugins: r.config.esbuild?.plugins?.length ? [p, ...r.config.esbuild?.plugins] : [p],
|
|
55
|
+
splitting: true,
|
|
56
|
+
treeShaking: true,
|
|
57
|
+
write: true
|
|
58
|
+
};
|
|
62
59
|
}
|
|
63
60
|
function defaultLoaders() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
return {
|
|
62
|
+
".woff": "file",
|
|
63
|
+
".woff2": "file"
|
|
64
|
+
};
|
|
68
65
|
}
|
|
69
|
-
// esbuild will append the .js or .css to output filenames
|
|
70
|
-
// keeping extension on entryPoints data for consistency
|
|
71
|
-
// and only trimming when creating esbuild opts
|
|
72
66
|
function mapEntryPointPaths(entryPoints) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
return entryPoints.map((entryPoint) => {
|
|
68
|
+
return {
|
|
69
|
+
in: entryPoint.in,
|
|
70
|
+
out: entryPoint.out.replace(/\.(tsx?|jsx?|css)$/, "")
|
|
71
|
+
};
|
|
72
|
+
});
|
|
79
73
|
}
|
|
80
74
|
const WORKER_CTOR_REGEX = /new(?:\s|\r?\n)+(?<ctor>(?:Shared)?Worker)(?:\s|\r?\n)*\((?:\s|\r?\n)*(?<url>.*?)(?:\s|\r?\n)*(?<end>[\),])/g;
|
|
81
75
|
const WORKER_URL_REGEX = /^('.*'|".*")$/;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
const loader = args.path.endsWith('ts') ? 'ts' : 'js';
|
|
136
|
-
return { contents, errors, loader };
|
|
137
|
-
});
|
|
138
|
-
build.onEnd((result) => {
|
|
139
|
-
if (result.metafile) {
|
|
140
|
-
r.completeBuild(result);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
},
|
|
144
|
-
};
|
|
76
|
+
function workersPlugin(r) {
|
|
77
|
+
return {
|
|
78
|
+
name: "@eighty4/dank/esbuild/workers",
|
|
79
|
+
setup(build) {
|
|
80
|
+
if (!build.initialOptions.metafile)
|
|
81
|
+
throw TypeError("plugin requires metafile");
|
|
82
|
+
build.onLoad({ filter: /\.(t|m?j)s$/ }, async (args) => {
|
|
83
|
+
let contents = await readFile(args.path, "utf8");
|
|
84
|
+
let offset = 0;
|
|
85
|
+
let errors = void 0;
|
|
86
|
+
for (const workerCtorMatch of contents.matchAll(WORKER_CTOR_REGEX)) {
|
|
87
|
+
if (!WORKER_URL_REGEX.test(workerCtorMatch.groups.url)) {
|
|
88
|
+
if (!errors)
|
|
89
|
+
errors = [];
|
|
90
|
+
errors.push(invalidWorkerUrlCtorArg(locationFromMatch(args, contents, workerCtorMatch), workerCtorMatch));
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (isIndexCommented(contents, workerCtorMatch.index)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const clientScript = args.path.replace(r.dirs.projectResolved, "").substring(1);
|
|
97
|
+
const workerUrl = workerCtorMatch.groups.url.substring(1, workerCtorMatch.groups.url.length - 1);
|
|
98
|
+
const workerEntryPoint = r.resolver.resolveHrefInPagesDir(clientScript, workerUrl);
|
|
99
|
+
if (workerEntryPoint === "outofbounds") {
|
|
100
|
+
if (!errors)
|
|
101
|
+
errors = [];
|
|
102
|
+
errors.push(outofboundsWorkerUrlCtorArg(locationFromMatch(args, contents, workerCtorMatch), workerCtorMatch));
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const workerCtor = workerCtorMatch.groups.ctor;
|
|
106
|
+
const workerUrlPlaceholder = workerEntryPoint.replace(/^pages/, "").replace(/\.(t|m?j)s$/, ".js");
|
|
107
|
+
const workerCtorReplacement = `new ${workerCtor}('${workerUrlPlaceholder}'${workerCtorMatch.groups.end}`;
|
|
108
|
+
contents = contents.substring(0, workerCtorMatch.index + offset) + workerCtorReplacement + contents.substring(workerCtorMatch.index + workerCtorMatch[0].length + offset);
|
|
109
|
+
offset += workerCtorReplacement.length - workerCtorMatch[0].length;
|
|
110
|
+
r.addWorker({
|
|
111
|
+
clientScript,
|
|
112
|
+
workerEntryPoint,
|
|
113
|
+
workerCtor,
|
|
114
|
+
workerUrl,
|
|
115
|
+
workerUrlPlaceholder
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
const loader = args.path.endsWith("ts") ? "ts" : "js";
|
|
119
|
+
return { contents, errors, loader };
|
|
120
|
+
});
|
|
121
|
+
build.onEnd((result) => {
|
|
122
|
+
if (result.metafile) {
|
|
123
|
+
r.completeBuild(result);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
145
128
|
}
|
|
146
129
|
function isIndexCommented(contents, index) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return blockCommented;
|
|
130
|
+
const preamble = contents.substring(0, index);
|
|
131
|
+
const lineIndex = preamble.lastIndexOf("\n") || 0;
|
|
132
|
+
const lineCommented = /\/\//.test(preamble.substring(lineIndex));
|
|
133
|
+
if (lineCommented) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
const blockCommentIndex = preamble.lastIndexOf("/*");
|
|
137
|
+
const blockCommented = blockCommentIndex !== -1 && preamble.substring(blockCommentIndex).indexOf("*/") === -1;
|
|
138
|
+
return blockCommented;
|
|
157
139
|
}
|
|
158
140
|
function locationFromMatch(args, contents, match) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
141
|
+
const preamble = contents.substring(0, match.index);
|
|
142
|
+
const line = preamble.match(/\n/g)?.length || 0;
|
|
143
|
+
let lineIndex = preamble.lastIndexOf("\n");
|
|
144
|
+
lineIndex = lineIndex === -1 ? 0 : lineIndex + 1;
|
|
145
|
+
const column = preamble.length - lineIndex;
|
|
146
|
+
const lineText = contents.substring(lineIndex, contents.indexOf("\n", lineIndex) || contents.length);
|
|
147
|
+
return {
|
|
148
|
+
lineText,
|
|
149
|
+
line,
|
|
150
|
+
column,
|
|
151
|
+
file: args.path,
|
|
152
|
+
length: match[0].length
|
|
153
|
+
};
|
|
172
154
|
}
|
|
173
155
|
function outofboundsWorkerUrlCtorArg(location, workerCtorMatch) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
156
|
+
return {
|
|
157
|
+
id: "worker-url-outofbounds",
|
|
158
|
+
text: `The ${workerCtorMatch.groups.ctor} constructor URL arg \`${workerCtorMatch.groups.url}\` cannot resolve to a path outside of the pages directory`,
|
|
159
|
+
location
|
|
160
|
+
};
|
|
179
161
|
}
|
|
180
162
|
function invalidWorkerUrlCtorArg(location, workerCtorMatch) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
163
|
+
return {
|
|
164
|
+
id: "worker-url-unresolvable",
|
|
165
|
+
text: `The ${workerCtorMatch.groups.ctor} constructor URL arg \`${workerCtorMatch.groups.url}\` must be a relative module path`,
|
|
166
|
+
location
|
|
167
|
+
};
|
|
186
168
|
}
|
|
169
|
+
export {
|
|
170
|
+
esbuildDevContext,
|
|
171
|
+
esbuildWebpages,
|
|
172
|
+
esbuildWorkers,
|
|
173
|
+
workersPlugin
|
|
174
|
+
};
|