odoro 1.0.4 → 1.0.6

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.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ export { buildProject, reportBuild } from './chunk-RZX7T3VG.js';
3
+ import './chunk-WPI53RD7.js';
4
+ import './chunk-LAMFWJB2.js';
5
+ import './chunk-JMEHF3KN.js';
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { estUneRessource } from './chunk-LAMFWJB2.js';
2
3
  import { success, info, colors } from './chunk-JMEHF3KN.js';
3
4
  import { existsSync, statSync, createReadStream } from 'fs';
4
5
  import { createServer } from 'http';
@@ -29,7 +30,13 @@ async function startPreviewServer(config, port = config.server.port + 1) {
29
30
  const relativePath = normalize(decodeURIComponent(path)).split(/[\\/]/).filter(Boolean).join("/");
30
31
  const candidate = join(config.outDir, relativePath);
31
32
  const dansLeDossier = ["index.html", "index.md"].map((nom) => join(candidate, nom)).find((chemin) => existsSync(chemin) && statSync(chemin).isFile());
32
- const file = existsSync(candidate) && statSync(candidate).isFile() ? candidate : dansLeDossier ?? join(config.outDir, "index.html");
33
+ const existant = existsSync(candidate) && statSync(candidate).isFile() ? candidate : dansLeDossier;
34
+ if (existant === void 0 && (extname(relativePath) !== "" || estUneRessource(incoming.headers))) {
35
+ response.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
36
+ response.end(`Introuvable : /${relativePath}`);
37
+ return;
38
+ }
39
+ const file = existant ?? join(config.outDir, "index.html");
33
40
  if (!file.startsWith(config.outDir)) {
34
41
  response.writeHead(403, { "Content-Type": "text/plain" });
35
42
  response.end("Interdit");
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env node
2
+ import { relative, resolve } from 'path';
3
+ import { build } from 'esbuild';
4
+
5
+ var DEPS_PREFIX = "/@deps/";
6
+ var INTERNAL_PREFIX = "/@odoro/";
7
+ var SOURCE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
8
+ var STYLE_EXTENSIONS = [".css"];
9
+ var ASSET_EXTENSIONS = [
10
+ ".svg",
11
+ ".png",
12
+ ".jpg",
13
+ ".jpeg",
14
+ ".gif",
15
+ ".webp",
16
+ ".avif",
17
+ ".ico",
18
+ ".woff",
19
+ ".woff2",
20
+ ".mp4",
21
+ ".webm"
22
+ ];
23
+ function depFileName(specifier) {
24
+ return `${specifier.replace(/^@/, "").split("/").join("_")}.js`;
25
+ }
26
+ function isBareSpecifier(specifier) {
27
+ return !specifier.startsWith(".") && !specifier.startsWith("/") && !specifier.startsWith("\\") && !/^[a-zA-Z]:[\\/]/.test(specifier) && !specifier.startsWith("data:") && !specifier.startsWith("http:") && !specifier.startsWith("https:");
28
+ }
29
+ function hasExtension(path, extensions) {
30
+ const clean = path.split("?")[0] ?? path;
31
+ return extensions.some((extension) => clean.toLowerCase().endsWith(extension));
32
+ }
33
+ function fileToUrl(file, root) {
34
+ const relativePath = relative(root, file).split("\\").join("/");
35
+ if (!relativePath.startsWith("..")) return `/${relativePath}`;
36
+ return `/@fs/${file.split("\\").join("/").replace(/^\//, "")}`;
37
+ }
38
+ function urlToFile(url, root) {
39
+ const path = (url.split("?")[0] ?? url).split("#")[0] ?? url;
40
+ if (path.startsWith("/@fs/")) {
41
+ const absolute = path.slice("/@fs/".length);
42
+ return /^[a-zA-Z]:/.test(absolute) ? absolute : `/${absolute}`;
43
+ }
44
+ return resolve(root, `.${path}`);
45
+ }
46
+ function applyAlias(specifier, config) {
47
+ for (const [prefix, target] of Object.entries(config.alias)) {
48
+ if (specifier === prefix || specifier.startsWith(`${prefix}/`)) {
49
+ return resolve(
50
+ config.root,
51
+ target,
52
+ specifier.slice(prefix.length).replace(/^\//, "")
53
+ );
54
+ }
55
+ }
56
+ return specifier;
57
+ }
58
+ function externalizeImports(config, dependencies) {
59
+ return {
60
+ name: "odoro-externalize",
61
+ setup(builder) {
62
+ builder.onResolve({ filter: /.*/ }, async (args) => {
63
+ if (args.kind === "entry-point") return null;
64
+ if (args.pluginData?.resolving === true) {
65
+ return null;
66
+ }
67
+ if (args.path.startsWith(INTERNAL_PREFIX) || args.path.startsWith(DEPS_PREFIX)) {
68
+ return { path: args.path, external: true };
69
+ }
70
+ const aliased = applyAlias(args.path, config);
71
+ const isFileLike = hasExtension(aliased, STYLE_EXTENSIONS) || hasExtension(aliased, ASSET_EXTENSIONS);
72
+ if (isBareSpecifier(aliased) && !isFileLike) {
73
+ return { path: `${DEPS_PREFIX}${depFileName(aliased)}`, external: true };
74
+ }
75
+ const resolved = await builder.resolve(aliased, {
76
+ kind: "import-statement",
77
+ resolveDir: args.resolveDir,
78
+ importer: args.importer,
79
+ pluginData: { resolving: true }
80
+ });
81
+ if (resolved.errors.length > 0) {
82
+ return { path: args.path, external: true };
83
+ }
84
+ dependencies.add(resolved.path);
85
+ const url = fileToUrl(resolved.path, config.root);
86
+ return {
87
+ path: hasExtension(url, ASSET_EXTENSIONS) ? `${url}?import` : url,
88
+ external: true
89
+ };
90
+ });
91
+ }
92
+ };
93
+ }
94
+ async function transformModule(file, config, env) {
95
+ const dependencies = /* @__PURE__ */ new Set();
96
+ const result = await build({
97
+ entryPoints: [file],
98
+ bundle: true,
99
+ write: false,
100
+ format: "esm",
101
+ platform: "browser",
102
+ target: "es2022",
103
+ sourcemap: "inline",
104
+ jsx: "automatic",
105
+ jsxDev: true,
106
+ logLevel: "silent",
107
+ absWorkingDir: config.root,
108
+ define: {
109
+ "import.meta.env": JSON.stringify(env),
110
+ "process.env.NODE_ENV": JSON.stringify("development"),
111
+ ...config.define
112
+ },
113
+ plugins: [externalizeImports(config, dependencies)]
114
+ });
115
+ const code = result.outputFiles[0]?.text;
116
+ if (code === void 0) {
117
+ throw new Error(`[odoro] La compilation de "${file}" n'a produit aucun code.`);
118
+ }
119
+ return { code, dependencies: [...dependencies] };
120
+ }
121
+ var DESTINATIONS_RESSOURCE = /* @__PURE__ */ new Set([
122
+ "script",
123
+ "style",
124
+ "image",
125
+ "font",
126
+ "audio",
127
+ "video",
128
+ "track",
129
+ "manifest",
130
+ "worker",
131
+ "sharedworker",
132
+ "serviceworker"
133
+ ]);
134
+ function estUneRessource(entetes) {
135
+ const destination = entetes["sec-fetch-dest"];
136
+ return typeof destination === "string" && DESTINATIONS_RESSOURCE.has(destination);
137
+ }
138
+ function feuilleDemandee(entetes, url) {
139
+ if (url.includes("?direct")) return true;
140
+ if (entetes["sec-fetch-dest"] === "style") return true;
141
+ const accepte = entetes["accept"];
142
+ return typeof accepte === "string" && accepte.includes("text/css");
143
+ }
144
+ function wrapStyle(url, css) {
145
+ return `const id = ${JSON.stringify(`odoro-style:${url}`)}
146
+ const css = ${JSON.stringify(css)}
147
+
148
+ let element = document.querySelector(\`style[data-odoro-id="\${id}"]\`)
149
+ if (element === null) {
150
+ element = document.createElement('style')
151
+ element.setAttribute('data-odoro-id', id)
152
+ document.head.appendChild(element)
153
+ }
154
+ element.textContent = css
155
+
156
+ import.meta.hot?.accept()
157
+ import.meta.hot?.dispose(() => {
158
+ // La feuille suivante recreera l'element : le retirer evite d'empiler les
159
+ // regles mortes a chaque rechargement.
160
+ element?.remove()
161
+ })
162
+ `;
163
+ }
164
+ function wrapAsset(url) {
165
+ return `export default ${JSON.stringify(url)}
166
+ `;
167
+ }
168
+
169
+ export { ASSET_EXTENSIONS, DEPS_PREFIX, INTERNAL_PREFIX, SOURCE_EXTENSIONS, STYLE_EXTENSIONS, applyAlias, depFileName, estUneRessource, feuilleDemandee, fileToUrl, hasExtension, isBareSpecifier, transformModule, urlToFile, wrapAsset, wrapStyle };
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { extractEntries, applyAlias, isBareSpecifier, fournisseurDe } from './chunk-2EE5QUCW.js';
2
+ import { extractEntries, fournisseurDe } from './chunk-WPI53RD7.js';
3
+ import { applyAlias, isBareSpecifier } from './chunk-LAMFWJB2.js';
3
4
  import { info, colors, size, success, duration } from './chunk-JMEHF3KN.js';
4
5
  import { existsSync } from 'fs';
5
6
  import { readFile, rm, mkdir, writeFile, cp, stat } from 'fs/promises';
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env node
2
+ import { depFileName, INTERNAL_PREFIX, DEPS_PREFIX, urlToFile, hasExtension, STYLE_EXTENSIONS, feuilleDemandee, ASSET_EXTENSIONS, wrapAsset, estUneRessource, SOURCE_EXTENSIONS, fileToUrl, transformModule, wrapStyle, applyAlias, isBareSpecifier } from './chunk-LAMFWJB2.js';
2
3
  import { info, error, success, duration, colors, warn } from './chunk-JMEHF3KN.js';
3
4
  import { existsSync, readFileSync, statSync, watch, createReadStream } from 'fs';
4
5
  import { readFile, rm, mkdir, writeFile } from 'fs/promises';
5
6
  import { createServer, request } from 'http';
6
- import { join, dirname, resolve, extname, relative } from 'path';
7
+ import { join, dirname, resolve, extname } from 'path';
7
8
  import { createRequire } from 'module';
8
9
  import { pathToFileURL, fileURLToPath } from 'url';
9
10
  import { createHash } from 'crypto';
@@ -296,146 +297,6 @@ function renderInteropProxy(info2) {
296
297
  return `${lines.join("\n")}
297
298
  `;
298
299
  }
299
- var DEPS_PREFIX = "/@deps/";
300
- var INTERNAL_PREFIX = "/@odoro/";
301
- var SOURCE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
302
- var STYLE_EXTENSIONS = [".css"];
303
- var ASSET_EXTENSIONS = [
304
- ".svg",
305
- ".png",
306
- ".jpg",
307
- ".jpeg",
308
- ".gif",
309
- ".webp",
310
- ".avif",
311
- ".ico",
312
- ".woff",
313
- ".woff2",
314
- ".mp4",
315
- ".webm"
316
- ];
317
- function depFileName(specifier) {
318
- return `${specifier.replace(/^@/, "").split("/").join("_")}.js`;
319
- }
320
- function isBareSpecifier(specifier) {
321
- return !specifier.startsWith(".") && !specifier.startsWith("/") && !specifier.startsWith("\\") && !/^[a-zA-Z]:[\\/]/.test(specifier) && !specifier.startsWith("data:") && !specifier.startsWith("http:") && !specifier.startsWith("https:");
322
- }
323
- function hasExtension(path, extensions) {
324
- const clean = path.split("?")[0] ?? path;
325
- return extensions.some((extension) => clean.toLowerCase().endsWith(extension));
326
- }
327
- function fileToUrl(file, root) {
328
- const relativePath = relative(root, file).split("\\").join("/");
329
- if (!relativePath.startsWith("..")) return `/${relativePath}`;
330
- return `/@fs/${file.split("\\").join("/").replace(/^\//, "")}`;
331
- }
332
- function urlToFile(url, root) {
333
- const path = (url.split("?")[0] ?? url).split("#")[0] ?? url;
334
- if (path.startsWith("/@fs/")) {
335
- const absolute = path.slice("/@fs/".length);
336
- return /^[a-zA-Z]:/.test(absolute) ? absolute : `/${absolute}`;
337
- }
338
- return resolve(root, `.${path}`);
339
- }
340
- function applyAlias(specifier, config) {
341
- for (const [prefix, target] of Object.entries(config.alias)) {
342
- if (specifier === prefix || specifier.startsWith(`${prefix}/`)) {
343
- return resolve(
344
- config.root,
345
- target,
346
- specifier.slice(prefix.length).replace(/^\//, "")
347
- );
348
- }
349
- }
350
- return specifier;
351
- }
352
- function externalizeImports(config, dependencies) {
353
- return {
354
- name: "odoro-externalize",
355
- setup(builder) {
356
- builder.onResolve({ filter: /.*/ }, async (args) => {
357
- if (args.kind === "entry-point") return null;
358
- if (args.pluginData?.resolving === true) {
359
- return null;
360
- }
361
- if (args.path.startsWith(INTERNAL_PREFIX) || args.path.startsWith(DEPS_PREFIX)) {
362
- return { path: args.path, external: true };
363
- }
364
- const aliased = applyAlias(args.path, config);
365
- const isFileLike = hasExtension(aliased, STYLE_EXTENSIONS) || hasExtension(aliased, ASSET_EXTENSIONS);
366
- if (isBareSpecifier(aliased) && !isFileLike) {
367
- return { path: `${DEPS_PREFIX}${depFileName(aliased)}`, external: true };
368
- }
369
- const resolved = await builder.resolve(aliased, {
370
- kind: "import-statement",
371
- resolveDir: args.resolveDir,
372
- importer: args.importer,
373
- pluginData: { resolving: true }
374
- });
375
- if (resolved.errors.length > 0) {
376
- return { path: args.path, external: true };
377
- }
378
- dependencies.add(resolved.path);
379
- const url = fileToUrl(resolved.path, config.root);
380
- return {
381
- path: hasExtension(url, ASSET_EXTENSIONS) ? `${url}?import` : url,
382
- external: true
383
- };
384
- });
385
- }
386
- };
387
- }
388
- async function transformModule(file, config, env) {
389
- const dependencies = /* @__PURE__ */ new Set();
390
- const result = await build({
391
- entryPoints: [file],
392
- bundle: true,
393
- write: false,
394
- format: "esm",
395
- platform: "browser",
396
- target: "es2022",
397
- sourcemap: "inline",
398
- jsx: "automatic",
399
- jsxDev: true,
400
- logLevel: "silent",
401
- absWorkingDir: config.root,
402
- define: {
403
- "import.meta.env": JSON.stringify(env),
404
- "process.env.NODE_ENV": JSON.stringify("development"),
405
- ...config.define
406
- },
407
- plugins: [externalizeImports(config, dependencies)]
408
- });
409
- const code = result.outputFiles[0]?.text;
410
- if (code === void 0) {
411
- throw new Error(`[odoro] La compilation de "${file}" n'a produit aucun code.`);
412
- }
413
- return { code, dependencies: [...dependencies] };
414
- }
415
- function wrapStyle(url, css) {
416
- return `const id = ${JSON.stringify(`odoro-style:${url}`)}
417
- const css = ${JSON.stringify(css)}
418
-
419
- let element = document.querySelector(\`style[data-odoro-id="\${id}"]\`)
420
- if (element === null) {
421
- element = document.createElement('style')
422
- element.setAttribute('data-odoro-id', id)
423
- document.head.appendChild(element)
424
- }
425
- element.textContent = css
426
-
427
- import.meta.hot?.accept()
428
- import.meta.hot?.dispose(() => {
429
- // La feuille suivante recreera l'element : le retirer evite d'empiler les
430
- // regles mortes a chaque rechargement.
431
- element?.remove()
432
- })
433
- `;
434
- }
435
- function wrapAsset(url) {
436
- return `export default ${JSON.stringify(url)}
437
- `;
438
- }
439
300
 
440
301
  // src/dev/deps.ts
441
302
  var MANIFEST = "manifest.json";
@@ -1111,7 +972,7 @@ async function startDevServer(config) {
1111
972
  const file = urlToFile(path, config.root);
1112
973
  if (existsSync(file) && statSync(file).isFile()) {
1113
974
  if (hasExtension(path, STYLE_EXTENSIONS)) {
1114
- await serveStyle(response, file, url2.includes("?direct"));
975
+ await serveStyle(response, file, feuilleDemandee(incoming.headers, url2));
1115
976
  return;
1116
977
  }
1117
978
  if (hasExtension(path, ASSET_EXTENSIONS)) {
@@ -1139,7 +1000,7 @@ async function startDevServer(config) {
1139
1000
  serveFile(response, index);
1140
1001
  return;
1141
1002
  }
1142
- if (!extname(path)) {
1003
+ if (!extname(path) && !estUneRessource(incoming.headers)) {
1143
1004
  await serveHtml(response);
1144
1005
  return;
1145
1006
  }
@@ -1217,4 +1078,4 @@ async function startDevServer(config) {
1217
1078
  };
1218
1079
  }
1219
1080
 
1220
- export { ModuleGraph, applyAlias, depFileName, detectSelfAccepting, extractEntries, fournisseurDe, injectClient, isBareSpecifier, optimizeDeps, scanDependencies, startDevServer };
1081
+ export { ModuleGraph, detectSelfAccepting, extractEntries, fournisseurDe, injectClient, optimizeDeps, scanDependencies, startDevServer };
package/dist/cli.js CHANGED
@@ -131,7 +131,7 @@ function rootFrom(flags, positional) {
131
131
  async function run(argv) {
132
132
  const { command, positional, flags } = parseArgs(argv);
133
133
  if (flags["version"] === true) {
134
- const manifest = await import('./package-5KU4PW5P.js');
134
+ const manifest = await import('./package-QDMDWXNK.js');
135
135
  console.log(manifest.default.version);
136
136
  return 0;
137
137
  }
@@ -142,7 +142,7 @@ async function run(argv) {
142
142
  switch (command) {
143
143
  case "create":
144
144
  case "new": {
145
- const { createCommand } = await import('./create-LVNBZOGV.js');
145
+ const { createCommand } = await import('./create-6FIQWINO.js');
146
146
  const options = {};
147
147
  if (positional[0] !== void 0) options.name = positional[0];
148
148
  if (typeof flags["template"] === "string") options.template = flags["template"];
@@ -156,20 +156,20 @@ async function run(argv) {
156
156
  return createCommand(options);
157
157
  }
158
158
  case "dev": {
159
- const { startDevServer } = await import('./server-DXOQAPVX.js');
159
+ const { startDevServer } = await import('./server-FZU7PFRY.js');
160
160
  const config = await loadConfig(rootFrom(flags, positional), overridesFrom(flags));
161
161
  await startDevServer(config);
162
162
  return new Promise(() => void 0);
163
163
  }
164
164
  case "build": {
165
- const { buildProject, reportBuild } = await import('./build-KI7IEVRJ.js');
165
+ const { buildProject, reportBuild } = await import('./build-ITT5BYZA.js');
166
166
  const config = await loadConfig(rootFrom(flags, positional), overridesFrom(flags));
167
167
  const output = await buildProject(config);
168
168
  reportBuild(output, process.cwd());
169
169
  return 0;
170
170
  }
171
171
  case "preview": {
172
- const { startPreviewServer } = await import('./preview-3K46Y23N.js');
172
+ const { startPreviewServer } = await import('./preview-ALGOUM4N.js');
173
173
  const config = await loadConfig(rootFrom(flags, positional), overridesFrom(flags));
174
174
  const port = numberFlag(flags, "port");
175
175
  await startPreviewServer(config, port);
@@ -148,8 +148,8 @@ var VERSIONS_FAMILLE = {
148
148
  "@odoro-cli/icons": "1.0.2",
149
149
  "@odoro-cli/libs": "1.0.2",
150
150
  "@odoro-cli/server": "1.0.2",
151
- "create-odoro": "1.0.4",
152
- "odoro": "1.0.4"
151
+ "create-odoro": "1.0.6",
152
+ "odoro": "1.0.6"
153
153
  };
154
154
 
155
155
  // src/scaffold/scaffold.ts
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
- export { startPreviewServer } from './chunk-34ES2ICQ.js';
2
+ export { startPreviewServer } from './chunk-DYMXQBIO.js';
3
3
  export { defineConfig, loadConfig } from './chunk-DL3NPC4H.js';
4
4
  import './chunk-T6RLHSCW.js';
5
- export { buildProject, reportBuild } from './chunk-FJYUQALD.js';
6
- export { ModuleGraph, depFileName, detectSelfAccepting, optimizeDeps, scanDependencies, startDevServer } from './chunk-2EE5QUCW.js';
5
+ export { buildProject, reportBuild } from './chunk-RZX7T3VG.js';
6
+ export { ModuleGraph, detectSelfAccepting, optimizeDeps, scanDependencies, startDevServer } from './chunk-WPI53RD7.js';
7
+ export { depFileName } from './chunk-LAMFWJB2.js';
7
8
  import './chunk-JMEHF3KN.js';
@@ -2,7 +2,7 @@
2
2
  // package.json
3
3
  var package_default = {
4
4
  name: "odoro",
5
- version: "1.0.4",
5
+ version: "1.0.6",
6
6
  type: "module",
7
7
  license: "UNLICENSED",
8
8
  author: "BouBouw",
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ export { startPreviewServer } from './chunk-DYMXQBIO.js';
3
+ import './chunk-LAMFWJB2.js';
4
+ import './chunk-JMEHF3KN.js';
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env node
2
- export { extractEntries, injectClient, startDevServer } from './chunk-2EE5QUCW.js';
2
+ export { extractEntries, injectClient, startDevServer } from './chunk-WPI53RD7.js';
3
+ import './chunk-LAMFWJB2.js';
3
4
  import './chunk-JMEHF3KN.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "odoro",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "author": "BouBouw",
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
- export { buildProject, reportBuild } from './chunk-FJYUQALD.js';
3
- import './chunk-2EE5QUCW.js';
4
- import './chunk-JMEHF3KN.js';
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export { startPreviewServer } from './chunk-34ES2ICQ.js';
3
- import './chunk-JMEHF3KN.js';