From ec9f15b233cdf751165c09e55d9b699c70136cc4 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sat, 23 Dec 2023 20:37:12 -0600 Subject: [PATCH 1/4] yea --- src/commands/publish.ts | 1 + src/index.ts | 1 + src/utilities/preprocessor.ts | 9 ++++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/commands/publish.ts b/src/commands/publish.ts index 781c662..574d2be 100644 --- a/src/commands/publish.ts +++ b/src/commands/publish.ts @@ -37,6 +37,7 @@ export async function publish(commandDir: string | undefined, args: Partial importDynamic('publish.js').then((m) => m.publish(...args))) ) diff --git a/src/utilities/preprocessor.ts b/src/utilities/preprocessor.ts index b4ef05b..a31785e 100644 --- a/src/utilities/preprocessor.ts +++ b/src/utilities/preprocessor.ts @@ -6,9 +6,9 @@ const processEnvType = (env: NodeJS.ProcessEnv) => { const envBuilder = new StringWriter(); for (const key of entries) { - envBuilder.tab(); - envBuilder.tab(); - envBuilder.envField(key); + envBuilder.tab() + .tab() + .envField(key); } return envBuilder.build(); }; @@ -40,6 +40,8 @@ const writeTsConfig = async (format: 'cjs' | 'esm', configPath: string, fw: File const target = format === 'esm' ? { target: 'esnext' } : {}; const sernTsConfig = { compilerOptions: { + //module determines top level await. CJS doesn't have that abliity afaik + module: format === 'cjs' ? 'node' : 'esnext', moduleResolution: 'node', strict: true, skipLibCheck: true, @@ -69,6 +71,7 @@ class StringWriter { return this; } envField(key: string) { + //if env field has space or parens, wrap key in "" if (/\s|\(|\)/g.test(key)) { this.fileString += `"${key}": string`; } else { From fe209e58c526d7cb3077ee46a35e216c6ccf5a56 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sat, 23 Dec 2023 23:39:38 -0600 Subject: [PATCH 2/4] ss\ --- src/commands/publish.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/commands/publish.ts b/src/commands/publish.ts index 574d2be..781c662 100644 --- a/src/commands/publish.ts +++ b/src/commands/publish.ts @@ -37,7 +37,6 @@ export async function publish(commandDir: string | undefined, args: Partial Date: Sat, 23 Dec 2023 23:39:54 -0600 Subject: [PATCH 3/4] restore --- src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 78a6936..0bfab5a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,7 +41,6 @@ program // .option('-i, --import [scriptPath...]', 'Prerequire a script to load into publisher') .option('-t, --token [token]') .option('--appId [applicationId]') - .option('-e, --env [envPath]', 'import an env file. default is looking in working directory') .argument('[path]', 'path with respect to current working directory that will locate all published files') .action(async (...args) => importDynamic('publish.js').then((m) => m.publish(...args))) ) From b5566db84591eb1f2cd942c3c2efb8379e631451 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 24 Dec 2023 10:36:21 -0600 Subject: [PATCH 4/4] fix: broken link and refactor --- src/commands/build.ts | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/commands/build.ts b/src/commands/build.ts index 1b6e879..b7e3534 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -54,19 +54,23 @@ export async function build(options: Record) { } const sernConfig = await getConfig(); let buildConfig: Partial = {}; + const entryPoints = await glob(`./src/**/*{${validExtensions.join(',')}}`, { //for some reason, my ignore glob wasn't registering correctly' ignore: { ignored: (p) => p.name.endsWith('.d.ts'), }, }); + const buildConfigPath = resolve(options.project ?? 'sern.build.js'); + const resolveBuildConfig = (path: string|undefined, language: string) => { if(language === 'javascript') { return path ?? resolve('jsconfig.json') } return path ?? resolve('tsconfig.json') } + const defaultBuildConfig = { defineVersion: true, format: options.format ?? 'esm', @@ -76,28 +80,23 @@ export async function build(options: Record) { env: options.env ?? resolve('.env'), }; if (pathExistsSync(buildConfigPath)) { - try { - buildConfig = { - ...defaultBuildConfig, - ...(await import('file:///' + buildConfigPath)).default, - }; - } catch (e) { - console.log(e); - process.exit(1); - } - } else { + //throwable, buildConfigPath may not exist buildConfig = { ...defaultBuildConfig, + ...(await import('file:///' + buildConfigPath)).default, }; + } else { + buildConfig = defaultBuildConfig; console.log('No build config found, defaulting'); } + let env = {} as Record; configDotenv({ path: buildConfig.env, processEnv: env }); - - if (env.MODE && !env.NODE_ENV) { + const modeButNotNodeEnvExists = env.MODE && !env.NODE_ENV; + if (modeButNotNodeEnvExists) { console.warn('Use NODE_ENV instead of MODE'); console.warn('MODE has no effect.'); - console.warn(`https://nodejs.dev/en/learn/nodejs-the-difference-between-development-and-production/`); + console.warn(`https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production`); } if (env.NODE_ENV) { @@ -110,7 +109,7 @@ export async function build(options: Record) { try { let config = require(buildConfig.tsconfig!); - config.extends && console.warn("Please ensure to extend the generated tsconfig") + config.extends && console.warn("Extend the generated tsconfig") } catch(e) { console.warn("no tsconfig / jsconfig found"); console.warn(`Please create a ${sernConfig.language === 'javascript' ? 'jsconfig.json' : 'tsconfig.json' }`); @@ -130,11 +129,11 @@ export async function build(options: Record) { console.log(' ', magentaBright('env'), buildConfig.env); const sernDir = resolve('.sern'), - genDir = resolve(sernDir, 'generated'), - ambientFilePath = resolve(sernDir, 'ambient.d.ts'), - packageJsonPath = resolve('package.json'), - sernTsConfigPath = resolve(sernDir, 'tsconfig.json'), - packageJson = () => require(packageJsonPath); + genDir = resolve(sernDir, 'generated'), + ambientFilePath = resolve(sernDir, 'ambient.d.ts'), + packageJsonPath = resolve('package.json'), + sernTsConfigPath = resolve(sernDir, 'tsconfig.json'), + packageJson = () => require(packageJsonPath); if (!(await pathExists(genDir))) { console.log('Making .sern/generated dir, does not exist');