Skip to content

Commit 71cd12e

Browse files
authored
Merge pull request #216 from underctrl-io/unbundled-dev
fix: operate in unbundled mode during dev
2 parents 8bc5358 + 608ec3e commit 71cd12e

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

packages/cache/src/use-cache-directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class UseCacheDirectivePlugin extends CommonDirectiveTransformer {
1414
...options,
1515
directive: 'use cache',
1616
importPath: '@commandkit/cache',
17-
importName: '__SECRET_USE_CACHE_INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED',
17+
importName: '$ckitiucw',
1818
asyncOnly: true,
1919
});
2020
}

packages/cache/src/use-cache.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const fnStore = new Map<
1616
memo: GenericFunction;
1717
}
1818
>();
19-
const DEFAULT_TTL = ms('15m');
2019
const CACHE_FN_ID = `__cache_fn_id_${Date.now()}__${Math.random()}__`;
2120
const CACHED_FN_SYMBOL = Symbol('commandkit.cache.sentinel');
2221

@@ -301,5 +300,13 @@ export function isCachedFunction(fn: GenericFunction): boolean {
301300
* @private
302301
* @internal
303302
*/
304-
export const __SECRET_USE_CACHE_INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: any =
305-
useCache;
303+
export const $ckitiucw: any = useCache;
304+
305+
if (!('$ckitiucw' in globalThis)) {
306+
Object.defineProperty(globalThis, '$ckitiucw', {
307+
value: useCache,
308+
configurable: false,
309+
enumerable: false,
310+
writable: false,
311+
});
312+
}

packages/commandkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
"picocolors": "^1.1.1",
119119
"rfdc": "^1.3.1",
120120
"rimraf": "^6.0.0",
121-
"tsdown": "^0.12.5",
121+
"tsdown": "^0.12.6",
122122
"use-macro": "^1.1.0"
123123
},
124124
"devDependencies": {

packages/commandkit/src/cli/build.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ export interface ApplicationBuildOptions {
1616
configPath?: string;
1717
}
1818

19+
// emit public env variables and given env variables
20+
function mergeDefinitionsIfNeeded(env: Record<string, string>) {
21+
const values = Object.fromEntries(
22+
Object.entries(process.env).filter(
23+
([k]) => !(k in env) && k.startsWith('COMMANDKIT_PUBLIC_'),
24+
),
25+
);
26+
27+
return {
28+
...env,
29+
...values,
30+
};
31+
}
32+
1933
export async function buildApplication({
2034
plugins,
2135
rolldownPlugins,
@@ -70,15 +84,15 @@ export async function buildApplication({
7084
sourcemap: true,
7185
target: 'node16',
7286
outDir: dest,
73-
env: config.env || {},
87+
env: mergeDefinitionsIfNeeded(config.env || {}),
7488
entry: [
7589
'src',
7690
`!${config.distDir}`,
7791
'!.commandkit',
7892
'!**/*.test.*',
7993
'!**/*.spec.*',
8094
],
81-
unbundle: false,
95+
unbundle: !!isDev,
8296
});
8397

8498
await copyLocaleFiles('src', dest);

packages/commandkit/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default defineConfig({
2020
cacheDirectivePlugin({
2121
directive: 'use cache',
2222
importPath: 'commandkit',
23-
importName: '__SECRET_USE_CACHE_INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED',
23+
importName: '$ckitiucw',
2424
asyncOnly: true,
2525
}),
2626
],

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)