odoro 1.0.6 → 1.0.8

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-22KJTV2R.js';
3
+ import './chunk-LHZGX5ML.js';
4
+ import './chunk-TQUJ3MFS.js';
5
+ import './chunk-JMEHF3KN.js';
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { extractEntries, fournisseurDe } from './chunk-WPI53RD7.js';
3
- import { applyAlias, isBareSpecifier } from './chunk-LAMFWJB2.js';
2
+ import { extractEntries, fournisseurDe } from './chunk-LHZGX5ML.js';
3
+ import { applyAlias, isBareSpecifier } from './chunk-TQUJ3MFS.js';
4
4
  import { info, colors, size, success, duration } from './chunk-JMEHF3KN.js';
5
5
  import { existsSync } from 'fs';
6
6
  import { readFile, rm, mkdir, writeFile, cp, stat } from 'fs/promises';
@@ -1,6 +1,6 @@
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';
3
- import { info, error, success, duration, colors, warn } from './chunk-JMEHF3KN.js';
2
+ import { depFileName, INTERNAL_PREFIX, DEPS_PREFIX, urlToFile, hasExtension, STYLE_EXTENSIONS, feuilleDemandee, ASSET_EXTENSIONS, wrapAsset, estUneRessource, wrapJson, SOURCE_EXTENSIONS, ecouter, fileToUrl, transformModule, wrapStyle, applyAlias, isBareSpecifier } from './chunk-TQUJ3MFS.js';
3
+ import { info, error, warn, success, duration, colors } from './chunk-JMEHF3KN.js';
4
4
  import { existsSync, readFileSync, statSync, watch, createReadStream } from 'fs';
5
5
  import { readFile, rm, mkdir, writeFile } from 'fs/promises';
6
6
  import { createServer, request } from 'http';
@@ -339,6 +339,20 @@ async function scanDependencies(config, entries) {
339
339
  return [...found].sort();
340
340
  }
341
341
  async function optimizeDeps(config, specifiers, force = false) {
342
+ try {
343
+ return await compilerDeps(config, specifiers, force);
344
+ } catch (cause) {
345
+ if (!estUneCourse(cause)) throw cause;
346
+ await new Promise((suite) => setTimeout(suite, DELAI_COURSE));
347
+ return compilerDeps(config, specifiers, force);
348
+ }
349
+ }
350
+ var DELAI_COURSE = 400;
351
+ function estUneCourse(cause) {
352
+ const code = cause?.code;
353
+ return code === "ENOENT" || code === "EPERM" || code === "EBUSY";
354
+ }
355
+ async function compilerDeps(config, specifiers, force) {
342
356
  const directory = join(config.root, "node_modules", ".odoro", "deps");
343
357
  const sorted = [...specifiers].sort();
344
358
  const hash = createHash("sha256").update(JSON.stringify(sorted)).update(await lockfileFingerprint(config.root)).update(entriesFingerprint(config.root, sorted)).update(engineVersion()).digest("hex").slice(0, 16);
@@ -987,6 +1001,15 @@ async function startDevServer(config) {
987
1001
  await serveScript(response, file);
988
1002
  return;
989
1003
  }
1004
+ if (hasExtension(path, [".json"])) {
1005
+ if (estUneRessource(incoming.headers) || url2.includes("?import")) {
1006
+ const json = await readFile(file, "utf8");
1007
+ send(response, wrapJson(json), MIME[".js"] ?? "text/javascript");
1008
+ } else {
1009
+ serveFile(response, file);
1010
+ }
1011
+ return;
1012
+ }
990
1013
  serveFile(response, file);
991
1014
  return;
992
1015
  }
@@ -1058,11 +1081,11 @@ async function startDevServer(config) {
1058
1081
  }
1059
1082
  }, 40);
1060
1083
  });
1061
- await new Promise((resolveListen, rejectListen) => {
1062
- server.once("error", rejectListen);
1063
- server.listen(config.server.port, config.server.host, resolveListen);
1064
- });
1065
- const url = `http://${config.server.host}:${config.server.port}${config.base}`;
1084
+ const { port, demande } = await ecouter(server, config.server.port, config.server.host);
1085
+ if (demande !== void 0) {
1086
+ warn(`port ${String(demande)} occupe \u2014 le serveur ecoute sur ${String(port)}`);
1087
+ }
1088
+ const url = `http://${config.server.host}:${String(port)}${config.base}`;
1066
1089
  success(`pret en ${duration(Date.now() - started)}`);
1067
1090
  info(` ${colors.cyan(url)}`);
1068
1091
  return {
@@ -2,6 +2,38 @@
2
2
  import { relative, resolve } from 'path';
3
3
  import { build } from 'esbuild';
4
4
 
5
+ // src/shared/ecouter.ts
6
+ var ESSAIS = 10;
7
+ async function ecouter(server, port, host, essais = ESSAIS) {
8
+ for (let decalage = 0; decalage < essais; decalage += 1) {
9
+ const candidat = port + decalage;
10
+ const pris = await new Promise((resolve2, reject) => {
11
+ const surErreur = (cause) => {
12
+ server.removeListener("listening", surEcoute);
13
+ if (cause.code === "EADDRINUSE") {
14
+ resolve2(true);
15
+ return;
16
+ }
17
+ reject(cause);
18
+ };
19
+ const surEcoute = () => {
20
+ server.removeListener("error", surErreur);
21
+ resolve2(false);
22
+ };
23
+ server.once("error", surErreur);
24
+ server.once("listening", surEcoute);
25
+ server.listen(candidat, host);
26
+ });
27
+ if (!pris) {
28
+ const adresse = server.address();
29
+ const obtenu = typeof adresse === "object" && adresse !== null ? adresse.port : candidat;
30
+ return decalage === 0 ? { port: obtenu } : { port: obtenu, demande: port };
31
+ }
32
+ }
33
+ throw new Error(
34
+ `[odoro] Aucun port libre entre ${String(port)} et ${String(port + essais - 1)}.`
35
+ );
36
+ }
5
37
  var DEPS_PREFIX = "/@deps/";
6
38
  var INTERNAL_PREFIX = "/@odoro/";
7
39
  var SOURCE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
@@ -118,6 +150,73 @@ async function transformModule(file, config, env) {
118
150
  }
119
151
  return { code, dependencies: [...dependencies] };
120
152
  }
153
+ var IDENTIFIANT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
154
+ var RESERVES = /* @__PURE__ */ new Set([
155
+ "arguments",
156
+ "await",
157
+ "break",
158
+ "case",
159
+ "catch",
160
+ "class",
161
+ "const",
162
+ "continue",
163
+ "debugger",
164
+ "default",
165
+ "delete",
166
+ "do",
167
+ "else",
168
+ "enum",
169
+ "eval",
170
+ "export",
171
+ "extends",
172
+ "false",
173
+ "finally",
174
+ "for",
175
+ "function",
176
+ "if",
177
+ "implements",
178
+ "import",
179
+ "in",
180
+ "instanceof",
181
+ "interface",
182
+ "let",
183
+ "new",
184
+ "null",
185
+ "package",
186
+ "private",
187
+ "protected",
188
+ "public",
189
+ "return",
190
+ "static",
191
+ "super",
192
+ "switch",
193
+ "this",
194
+ "throw",
195
+ "true",
196
+ "try",
197
+ "typeof",
198
+ "var",
199
+ "void",
200
+ "while",
201
+ "with",
202
+ "yield"
203
+ ]);
204
+ function wrapJson(json) {
205
+ let valeur;
206
+ try {
207
+ valeur = JSON.parse(json);
208
+ } catch {
209
+ return 'throw new SyntaxError("JSON illisible")';
210
+ }
211
+ const lignes = ["export default " + json.trim()];
212
+ if (typeof valeur === "object" && valeur !== null && !Array.isArray(valeur)) {
213
+ for (const [cle, contenu] of Object.entries(valeur)) {
214
+ if (!IDENTIFIANT.test(cle) || RESERVES.has(cle)) continue;
215
+ lignes.push("export const " + cle + " = " + JSON.stringify(contenu));
216
+ }
217
+ }
218
+ return lignes.join("\n");
219
+ }
121
220
  var DESTINATIONS_RESSOURCE = /* @__PURE__ */ new Set([
122
221
  "script",
123
222
  "style",
@@ -166,4 +265,4 @@ function wrapAsset(url) {
166
265
  `;
167
266
  }
168
267
 
169
- export { ASSET_EXTENSIONS, DEPS_PREFIX, INTERNAL_PREFIX, SOURCE_EXTENSIONS, STYLE_EXTENSIONS, applyAlias, depFileName, estUneRessource, feuilleDemandee, fileToUrl, hasExtension, isBareSpecifier, transformModule, urlToFile, wrapAsset, wrapStyle };
268
+ export { ASSET_EXTENSIONS, DEPS_PREFIX, INTERNAL_PREFIX, SOURCE_EXTENSIONS, STYLE_EXTENSIONS, applyAlias, depFileName, ecouter, estUneRessource, feuilleDemandee, fileToUrl, hasExtension, isBareSpecifier, transformModule, urlToFile, wrapAsset, wrapJson, wrapStyle };
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { estUneRessource } from './chunk-LAMFWJB2.js';
3
- import { success, info, colors } from './chunk-JMEHF3KN.js';
2
+ import { estUneRessource, ecouter } from './chunk-TQUJ3MFS.js';
3
+ import { warn, success, info, colors } from './chunk-JMEHF3KN.js';
4
4
  import { existsSync, statSync, createReadStream } from 'fs';
5
5
  import { createServer } from 'http';
6
6
  import { normalize, join, extname } from 'path';
@@ -50,11 +50,11 @@ async function startPreviewServer(config, port = config.server.port + 1) {
50
50
  });
51
51
  createReadStream(file).pipe(response);
52
52
  });
53
- await new Promise((done, fail) => {
54
- server.once("error", fail);
55
- server.listen(port, config.server.host, done);
56
- });
57
- const url = `http://${config.server.host}:${port}${config.base}`;
53
+ const { port: obtenu, demande } = await ecouter(server, port, config.server.host);
54
+ if (demande !== void 0) {
55
+ warn(`port ${String(demande)} occupe \u2014 l apercu ecoute sur ${String(obtenu)}`);
56
+ }
57
+ const url = `http://${config.server.host}:${String(obtenu)}${config.base}`;
58
58
  success("previsualisation du build de production");
59
59
  info(` ${colors.cyan(url)}`);
60
60
  return {
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-QDMDWXNK.js');
134
+ const manifest = await import('./package-NBP5NDX6.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-6FIQWINO.js');
145
+ const { createCommand } = await import('./create-CDKS7KZ3.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-FZU7PFRY.js');
159
+ const { startDevServer } = await import('./server-4UGN3SFS.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-ITT5BYZA.js');
165
+ const { buildProject, reportBuild } = await import('./build-JFQHODAT.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-ALGOUM4N.js');
172
+ const { startPreviewServer } = await import('./preview-7DKEAQOQ.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.6",
152
- "odoro": "1.0.6"
151
+ "create-odoro": "1.0.8",
152
+ "odoro": "1.0.8"
153
153
  };
154
154
 
155
155
  // src/scaffold/scaffold.ts
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- export { startPreviewServer } from './chunk-DYMXQBIO.js';
2
+ export { startPreviewServer } from './chunk-ZVL7EXJO.js';
3
3
  export { defineConfig, loadConfig } from './chunk-DL3NPC4H.js';
4
4
  import './chunk-T6RLHSCW.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';
5
+ export { buildProject, reportBuild } from './chunk-22KJTV2R.js';
6
+ export { ModuleGraph, detectSelfAccepting, optimizeDeps, scanDependencies, startDevServer } from './chunk-LHZGX5ML.js';
7
+ export { depFileName } from './chunk-TQUJ3MFS.js';
8
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.6",
5
+ version: "1.0.8",
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-ZVL7EXJO.js';
3
+ import './chunk-TQUJ3MFS.js';
4
+ import './chunk-JMEHF3KN.js';
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- export { extractEntries, injectClient, startDevServer } from './chunk-WPI53RD7.js';
3
- import './chunk-LAMFWJB2.js';
2
+ export { extractEntries, injectClient, startDevServer } from './chunk-LHZGX5ML.js';
3
+ import './chunk-TQUJ3MFS.js';
4
4
  import './chunk-JMEHF3KN.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "odoro",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "author": "BouBouw",
@@ -1,5 +0,0 @@
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 +0,0 @@
1
- #!/usr/bin/env node
2
- export { startPreviewServer } from './chunk-DYMXQBIO.js';
3
- import './chunk-LAMFWJB2.js';
4
- import './chunk-JMEHF3KN.js';