@junobuild/config-loader 0.3.1 → 0.4.0
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.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire as topLevelCreateRequire } from 'module';
|
|
2
2
|
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
-
var f=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(o,e)=>(typeof require<"u"?require:o)[e]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});import{existsSync as c,readFileSync as F}from"node:fs";import{access as T,lstat as h,readFile as
|
|
3
|
+
var f=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(o,e)=>(typeof require<"u"?require:o)[e]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});import{existsSync as c,readFileSync as F}from"node:fs";import{access as T,lstat as h,readFile as J}from"node:fs/promises";import{extname as x,join as r}from"node:path";import{transformFileSync as j}from"@babel/core";import*as u from"@babel/plugin-transform-modules-commonjs";import*as a from"@babel/preset-typescript";import{defineConfig as m,defineConsoleConfig as y}from"@junobuild/config";var p=({id:n,extension:o})=>{delete f.cache[n];let e=f("module"),t=e._load;try{return f.extensions[o]=(i,s)=>{let C=j(s,{presets:[a.default],plugins:[u.default]}).code;i._compile(C,s)},e._load=function(i){return i==="@junobuild/config"?{defineConfig:s=>m(s),defineConsoleConfig:s=>y(s)}:t.apply(this,arguments)},f(n)}finally{f.extensions[o]=void 0,e._load=t}};var _=async n=>{try{let{configPath:o}=l(n);return await T(o),(await h(o)).isFile()}catch(o){if(o instanceof Error&&"code"in o&&o.code==="ENOENT")return!1;throw o}},g=n=>r(process.cwd(),`${n}.ts`),w=n=>r(process.cwd(),`${n}.js`),d=n=>r(process.cwd(),`${n}.mjs`),l=({filename:n})=>{let o=g(n);if(c(o))return{configPath:o,configType:"ts"};let e=w(n);if(c(e))return{configPath:e,configType:"js"};let t=d(n);if(c(t))return{configPath:t,configType:"js"};let i=r(process.cwd(),`${n}.cjs`);if(c(i))return{configPath:i,configType:"js"};let s=r(process.cwd(),`${n.replace(".config","")}.json`);return c(s)?{configPath:s,configType:"json"}:{configPath:r(process.cwd(),`${n}.json`),configType:"json"}},$=({filename:n})=>{let o=r(process.cwd(),"tsconfig.json");if(c(o))return{configPath:g(n),configType:"ts"};try{let e=r(process.cwd(),"package.json");if(c(e)){let t=JSON.parse(F(e,"utf8"));if("typescript"in(t.dependencies??{})||"typescript"in(t.devDependencies??{}))return{configPath:g(n),configType:"ts"};if(t.type==="module")return{configPath:d(n),configType:"js"}}}catch{}},R=async({config:n,...o})=>{let{configPath:e,configType:t}=l({...o});switch(t){case"ts":case"js":{let{default:i}=p({id:e,extension:x(e)});return n(i)}default:{let i=await J(e);return JSON.parse(i.toString("utf-8"))}}};export{$ as detectJunoConfigType,_ as junoConfigExist,l as junoConfigFile,R as readJunoConfig};
|
|
4
4
|
//# sourceMappingURL=index.mjs.map
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/configs/juno.config.ts", "../../src/utils/node.utils.ts"],
|
|
4
|
-
"sourcesContent": ["import type {
|
|
5
|
-
"mappings": ";;
|
|
6
|
-
"names": ["existsSync", "readFileSync", "access", "lstat", "readFile", "extname", "join", "transformFileSync", "mod", "ts", "defineConfig", "defineConsoleConfig", "
|
|
4
|
+
"sourcesContent": ["import type {JunoConfig, JunoConfigFnOrObject} from '@junobuild/config';\nimport {existsSync, readFileSync} from 'node:fs';\nimport {access, lstat, readFile} from 'node:fs/promises';\nimport {extname, join} from 'node:path';\nimport type {ConfigFile, ConfigFilename} from '../types/config';\nimport {nodeRequire} from '../utils/node.utils';\n\nexport const junoConfigExist = async (params: {filename: ConfigFilename}): Promise<boolean> => {\n try {\n const {configPath} = junoConfigFile(params);\n\n // We can access the file - i.e. it exists.\n await access(configPath);\n\n // We also double check it's a file and not a directory.\n // Note: A directory can be created by and on Docker start when the referenced config file in the docker-compose.yml file does not point to an existing file.\n return (await lstat(configPath)).isFile();\n } catch (err: unknown) {\n if (err instanceof Error && 'code' in err && (err as NodeJS.ErrnoException).code === 'ENOENT') {\n return false;\n }\n throw err;\n }\n};\n\nconst ts = (filename: ConfigFilename): string => join(process.cwd(), `${filename}.ts`);\nconst js = (filename: ConfigFilename): string => join(process.cwd(), `${filename}.js`);\nconst mjs = (filename: ConfigFilename): string => join(process.cwd(), `${filename}.mjs`);\n\nexport const junoConfigFile = ({filename}: {filename: ConfigFilename}): ConfigFile => {\n const junoTs = ts(filename);\n\n if (existsSync(junoTs)) {\n return {\n configPath: junoTs,\n configType: 'ts'\n };\n }\n\n const junoJs = js(filename);\n\n if (existsSync(junoJs)) {\n return {\n configPath: junoJs,\n configType: 'js'\n };\n }\n\n const junoMjs = mjs(filename);\n\n if (existsSync(junoMjs)) {\n return {\n configPath: junoMjs,\n configType: 'js'\n };\n }\n\n const junoCjs = join(process.cwd(), `${filename}.cjs`);\n\n if (existsSync(junoCjs)) {\n return {\n configPath: junoCjs,\n configType: 'js'\n };\n }\n\n // Support for original juno.json or juno.dev.json file\n // juno.config || juno.dev.config => juno.json || juno.dev.json\n const junoJsonDeprecated = join(process.cwd(), `${filename.replace('.config', '')}.json`);\n\n if (existsSync(junoJsonDeprecated)) {\n return {\n configPath: junoJsonDeprecated,\n configType: 'json'\n };\n }\n\n return {\n configPath: join(process.cwd(), `${filename}.json`),\n configType: 'json'\n };\n};\n\nexport const detectJunoConfigType = ({\n filename\n}: {\n filename: ConfigFilename;\n}): ConfigFile | undefined => {\n const tsconfig = join(process.cwd(), 'tsconfig.json');\n\n if (existsSync(tsconfig)) {\n const junoTs = ts(filename);\n\n return {\n configPath: junoTs,\n configType: 'ts'\n };\n }\n\n try {\n const packageJsonPath = join(process.cwd(), 'package.json');\n\n if (existsSync(packageJsonPath)) {\n interface PackageJson {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n type?: string;\n }\n\n const packageJson: PackageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));\n\n if (\n 'typescript' in (packageJson.dependencies ?? {}) ||\n 'typescript' in (packageJson.devDependencies ?? {})\n ) {\n const junoTs = ts(filename);\n\n return {\n configPath: junoTs,\n configType: 'ts'\n };\n }\n\n if (packageJson.type === 'module') {\n const junoMjs = mjs(filename);\n\n return {\n configPath: junoMjs,\n configType: 'js'\n };\n }\n }\n } catch (_error: unknown) {\n // We ignore the error as returning undefined will lead the CLI to ask the user what type of configuration type should be used.\n }\n\n return undefined;\n};\n\nexport const readJunoConfig = async <\n ConfigFnOrObject extends JunoConfigFnOrObject,\n Config extends JunoConfig\n>({\n config,\n ...rest\n}: {\n filename: ConfigFilename;\n config: (userConfig: ConfigFnOrObject) => Config;\n}): Promise<Config> => {\n const {configPath, configType} = junoConfigFile({...rest});\n\n switch (configType) {\n case 'ts':\n case 'js': {\n const {default: userConfig} = nodeRequire<ConfigFnOrObject>({\n id: configPath,\n extension: extname(configPath)\n });\n return config(userConfig);\n }\n default: {\n const buffer = await readFile(configPath);\n return JSON.parse(buffer.toString('utf-8'));\n }\n }\n};\n", "import {transformFileSync} from '@babel/core';\nimport * as mod from '@babel/plugin-transform-modules-commonjs';\nimport * as ts from '@babel/preset-typescript';\nimport {\n defineConfig,\n defineConsoleConfig,\n type JunoConfig,\n type JunoConsoleConfig\n} from '@junobuild/config';\n\n/**\n * Adapted source from Stencil (https://github.com/ionic-team/stencil/blob/main/src/compiler/sys/node-require.ts)\n */\nexport const nodeRequire = <T>({id, extension}: {id: string; extension: string}): {default: T} => {\n // ensure we cleared out node's internal require() cache for this file\n delete require.cache[id];\n\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const Module = require('module');\n const originalLoad = Module._load;\n\n try {\n // let's override node's require for a second\n // don't worry, we'll revert this when we're done\n // eslint-disable-next-line local-rules/prefer-object-params\n require.extensions[extension] = (module: NodeJS.Module, fileName: string) => {\n // let's transpile with Babel regardless if TS or JS\n const sourceText = transformFileSync(fileName, {\n presets: [ts.default],\n plugins: [mod.default]\n }).code;\n\n interface NodeModuleWithCompile extends NodeModule {\n _compile(code: string, filename: string): T;\n }\n\n // we need to coerce because of the requirements for the arguments to\n // this function.\n (module as NodeModuleWithCompile)._compile(sourceText, fileName);\n };\n\n // We override defineConfig because the library is unknown in the module we are trying to load.\n // This need to be a function and not an arrow function because of the \"arguments\"\n Module._load = function (request: string): unknown {\n if (request === '@junobuild/config') {\n return {\n defineConfig: (config: JunoConfig) => defineConfig(config),\n defineConsoleConfig: (config: JunoConsoleConfig) => defineConsoleConfig(config)\n };\n }\n\n // eslint-disable-next-line prefer-rest-params\n return originalLoad.apply(this, arguments);\n };\n\n // let's do this!\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n return require(id);\n } finally {\n // all set, let's go ahead and reset the require back to the default\n require.extensions[extension] = undefined;\n\n // Redo our hack\n Module._load = originalLoad;\n }\n};\n"],
|
|
5
|
+
"mappings": ";;yPACA,OAAQ,cAAAA,EAAY,gBAAAC,MAAmB,UACvC,OAAQ,UAAAC,EAAQ,SAAAC,EAAO,YAAAC,MAAe,mBACtC,OAAQ,WAAAC,EAAS,QAAAC,MAAW,YCH5B,OAAQ,qBAAAC,MAAwB,cAChC,UAAYC,MAAS,2CACrB,UAAYC,MAAQ,2BACpB,OACE,gBAAAC,EACA,uBAAAC,MAGK,oBAKA,IAAMC,EAAc,CAAI,CAAC,GAAAC,EAAI,UAAAC,CAAS,IAAqD,CAEhG,OAAOC,EAAQ,MAAMF,CAAE,EAGvB,IAAMG,EAAS,EAAQ,QAAQ,EACzBC,EAAeD,EAAO,MAE5B,GAAI,CAIF,OAAAD,EAAQ,WAAWD,CAAS,EAAI,CAACI,EAAuBC,IAAqB,CAE3E,IAAMC,EAAaC,EAAkBF,EAAU,C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AU,CAC/B,CAAC,EACD,OAAOsB,EAAOG,CAAU,CAC1B,CACA,QAAS,CACP,IAAMG,EAAS,MAAMC,EAAS7B,CAAU,EACxC,OAAO,KAAK,MAAM4B,EAAO,SAAS,OAAO,CAAC,CAC5C,CACF,CACF",
|
|
6
|
+
"names": ["existsSync", "readFileSync", "access", "lstat", "readFile", "extname", "join", "transformFileSync", "mod", "ts", "defineConfig", "defineConsoleConfig", "nodeRequire", "id", "extension", "__require", "Module", "originalLoad", "module", "fileName", "sourceText", "transformFileSync", "request", "config", "defineConfig", "defineConsoleConfig", "junoConfigExist", "params", "configPath", "junoConfigFile", "access", "lstat", "err", "ts", "filename", "join", "js", "mjs", "junoTs", "existsSync", "junoJs", "junoMjs", "junoCjs", "junoJsonDeprecated", "detectJunoConfigType", "tsconfig", "packageJsonPath", "packageJson", "readFileSync", "readJunoConfig", "config", "rest", "configType", "userConfig", "nodeRequire", "extname", "buffer", "readFile"]
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { JunoConfig, JunoConfigFnOrObject
|
|
1
|
+
import type { JunoConfig, JunoConfigFnOrObject } from '@junobuild/config';
|
|
2
2
|
import type { ConfigFile, ConfigFilename } from '../types/config';
|
|
3
3
|
export declare const junoConfigExist: (params: {
|
|
4
4
|
filename: ConfigFilename;
|
|
@@ -9,7 +9,7 @@ export declare const junoConfigFile: ({ filename }: {
|
|
|
9
9
|
export declare const detectJunoConfigType: ({ filename }: {
|
|
10
10
|
filename: ConfigFilename;
|
|
11
11
|
}) => ConfigFile | undefined;
|
|
12
|
-
export declare const readJunoConfig: <ConfigFnOrObject extends JunoConfigFnOrObject
|
|
12
|
+
export declare const readJunoConfig: <ConfigFnOrObject extends JunoConfigFnOrObject, Config extends JunoConfig>({ config, ...rest }: {
|
|
13
13
|
filename: ConfigFilename;
|
|
14
14
|
config: (userConfig: ConfigFnOrObject) => Config;
|
|
15
15
|
}) => Promise<Config>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junobuild/config-loader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Utilities for reading Juno's configuration settings.",
|
|
5
5
|
"author": "David Dal Busco (https://daviddalbusco.com)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
],
|
|
48
48
|
"homepage": "https://juno.build",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@babel/core": "^7.
|
|
51
|
-
"@babel/plugin-transform-modules-commonjs": "^7.
|
|
52
|
-
"@babel/preset-typescript": "^7.
|
|
50
|
+
"@babel/core": "^7.28.0",
|
|
51
|
+
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
|
|
52
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
53
53
|
"@junobuild/config": "*"
|
|
54
54
|
}
|
|
55
55
|
}
|