@latticexyz/config 2.0.0-next.10 → 2.0.0-next.12
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/dist/node/index.js.map +1 -1
- package/package.json +3 -3
- package/src/node/loadConfig.ts +2 -0
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/node/loadConfig.ts"],"sourcesContent":["import { findUp } from \"find-up\";\nimport path from \"path\";\nimport { NotInsideProjectError } from \"../library/errors\";\nimport esbuild from \"esbuild\";\nimport { rmSync } from \"fs\";\nimport { pathToFileURL } from \"url\";\nimport os from \"os\";\n\n// In order of preference files are checked\nconst configFiles = [\"mud.config.js\", \"mud.config.mjs\", \"mud.config.ts\", \"mud.config.mts\"];\nconst TEMP_CONFIG = \"mud.config.temp.mjs\";\n\nexport async function loadConfig(configPath?: string): Promise<unknown> {\n configPath = await resolveConfigPath(configPath);\n try {\n await esbuild.build({\n entryPoints: [configPath],\n format: \"esm\",\n outfile: TEMP_CONFIG,\n // https://esbuild.github.io/getting-started/#bundling-for-node\n platform: \"node\",\n // bundle local imports (otherwise it may error, js can't import ts)\n bundle: true,\n // avoid bundling external imports (it's unnecessary and esbuild can't handle all node features)\n packages: \"external\",\n });\n configPath = await resolveConfigPath(TEMP_CONFIG, true);\n // Node.js caches dynamic imports, so without appending a cache breaking\n // param like `?update={Date.now()}` this import always returns the same config\n // if called multiple times in a single process, like the `dev-contracts` cli\n return (await import(configPath + `?update=${Date.now()}`)).default;\n } finally {\n rmSync(TEMP_CONFIG, { force: true });\n }\n}\n\nexport async function resolveConfigPath(configPath: string | undefined, toFileURL?: boolean) {\n if (configPath === undefined) {\n configPath = await getUserConfigPath();\n } else {\n if (!path.isAbsolute(configPath)) {\n configPath = path.join(process.cwd(), configPath);\n configPath = path.normalize(configPath);\n }\n }\n\n // Add `file:///` for Windows support\n // (see https://github.com/nodejs/node/issues/31710)\n return toFileURL && os.platform() === \"win32\" ? pathToFileURL(configPath).href : configPath;\n}\n\nasync function getUserConfigPath() {\n const tsConfigPath = await findUp(configFiles);\n if (tsConfigPath === undefined) {\n throw new NotInsideProjectError();\n }\n return tsConfigPath;\n}\n"],"mappings":"yCAAA,OAAS,UAAAA,MAAc,UACvB,OAAOC,MAAU,OAEjB,OAAOC,MAAa,UACpB,OAAS,UAAAC,MAAc,KACvB,OAAS,iBAAAC,MAAqB,MAC9B,OAAOC,MAAQ,
|
|
1
|
+
{"version":3,"sources":["../../src/node/loadConfig.ts"],"sourcesContent":["import { findUp } from \"find-up\";\nimport path from \"path\";\nimport { NotInsideProjectError } from \"../library/errors\";\nimport esbuild from \"esbuild\";\nimport { rmSync } from \"fs\";\nimport { pathToFileURL } from \"url\";\nimport os from \"os\";\n\n// TODO: explore using https://www.npmjs.com/package/ts-import instead\n\n// In order of preference files are checked\nconst configFiles = [\"mud.config.js\", \"mud.config.mjs\", \"mud.config.ts\", \"mud.config.mts\"];\nconst TEMP_CONFIG = \"mud.config.temp.mjs\";\n\nexport async function loadConfig(configPath?: string): Promise<unknown> {\n configPath = await resolveConfigPath(configPath);\n try {\n await esbuild.build({\n entryPoints: [configPath],\n format: \"esm\",\n outfile: TEMP_CONFIG,\n // https://esbuild.github.io/getting-started/#bundling-for-node\n platform: \"node\",\n // bundle local imports (otherwise it may error, js can't import ts)\n bundle: true,\n // avoid bundling external imports (it's unnecessary and esbuild can't handle all node features)\n packages: \"external\",\n });\n configPath = await resolveConfigPath(TEMP_CONFIG, true);\n // Node.js caches dynamic imports, so without appending a cache breaking\n // param like `?update={Date.now()}` this import always returns the same config\n // if called multiple times in a single process, like the `dev-contracts` cli\n return (await import(configPath + `?update=${Date.now()}`)).default;\n } finally {\n rmSync(TEMP_CONFIG, { force: true });\n }\n}\n\nexport async function resolveConfigPath(configPath: string | undefined, toFileURL?: boolean) {\n if (configPath === undefined) {\n configPath = await getUserConfigPath();\n } else {\n if (!path.isAbsolute(configPath)) {\n configPath = path.join(process.cwd(), configPath);\n configPath = path.normalize(configPath);\n }\n }\n\n // Add `file:///` for Windows support\n // (see https://github.com/nodejs/node/issues/31710)\n return toFileURL && os.platform() === \"win32\" ? pathToFileURL(configPath).href : configPath;\n}\n\nasync function getUserConfigPath() {\n const tsConfigPath = await findUp(configFiles);\n if (tsConfigPath === undefined) {\n throw new NotInsideProjectError();\n }\n return tsConfigPath;\n}\n"],"mappings":"yCAAA,OAAS,UAAAA,MAAc,UACvB,OAAOC,MAAU,OAEjB,OAAOC,MAAa,UACpB,OAAS,UAAAC,MAAc,KACvB,OAAS,iBAAAC,MAAqB,MAC9B,OAAOC,MAAQ,KAKf,IAAMC,EAAc,CAAC,gBAAiB,iBAAkB,gBAAiB,gBAAgB,EACnFC,EAAc,sBAEpB,eAAsBC,EAAWC,EAAuC,CACtEA,EAAa,MAAMC,EAAkBD,CAAU,EAC/C,GAAI,CACF,aAAMP,EAAQ,MAAM,CAClB,YAAa,CAACO,CAAU,EACxB,OAAQ,MACR,QAASF,EAET,SAAU,OAEV,OAAQ,GAER,SAAU,UACZ,CAAC,EACDE,EAAa,MAAMC,EAAkBH,EAAa,EAAI,GAI9C,MAAM,OAAOE,EAAa,WAAW,KAAK,IAAI,MAAM,OAC9D,QAAE,CACAN,EAAOI,EAAa,CAAE,MAAO,EAAK,CAAC,CACrC,CACF,CAEA,eAAsBG,EAAkBD,EAAgCE,EAAqB,CAC3F,OAAIF,IAAe,OACjBA,EAAa,MAAMG,EAAkB,EAEhCC,EAAK,WAAWJ,CAAU,IAC7BA,EAAaI,EAAK,KAAK,QAAQ,IAAI,EAAGJ,CAAU,EAChDA,EAAaI,EAAK,UAAUJ,CAAU,GAMnCE,GAAaN,EAAG,SAAS,IAAM,QAAUD,EAAcK,CAAU,EAAE,KAAOA,CACnF,CAEA,eAAeG,GAAoB,CACjC,IAAME,EAAe,MAAMC,EAAOT,CAAW,EAC7C,GAAIQ,IAAiB,OACnB,MAAM,IAAIE,EAEZ,OAAOF,CACT","names":["findUp","path","esbuild","rmSync","pathToFileURL","os","configFiles","TEMP_CONFIG","loadConfig","configPath","resolveConfigPath","toFileURL","getUserConfigPath","path","tsConfigPath","findUp","NotInsideProjectError"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latticexyz/config",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.12",
|
|
4
4
|
"description": "Config for Store and World",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"find-up": "^6.3.0",
|
|
35
35
|
"zod": "^3.21.4",
|
|
36
36
|
"zod-validation-error": "^1.3.0",
|
|
37
|
-
"@latticexyz/common": "2.0.0-next.
|
|
38
|
-
"@latticexyz/schema-type": "2.0.0-next.
|
|
37
|
+
"@latticexyz/common": "2.0.0-next.12",
|
|
38
|
+
"@latticexyz/schema-type": "2.0.0-next.12"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"tsup": "^6.7.0"
|
package/src/node/loadConfig.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { rmSync } from "fs";
|
|
|
6
6
|
import { pathToFileURL } from "url";
|
|
7
7
|
import os from "os";
|
|
8
8
|
|
|
9
|
+
// TODO: explore using https://www.npmjs.com/package/ts-import instead
|
|
10
|
+
|
|
9
11
|
// In order of preference files are checked
|
|
10
12
|
const configFiles = ["mud.config.js", "mud.config.mjs", "mud.config.ts", "mud.config.mts"];
|
|
11
13
|
const TEMP_CONFIG = "mud.config.temp.mjs";
|