Ver código fonte

Replace __DEV__ with NODE_ENV is not production (#102)

Loris Leiva 1 ano atrás
pai
commit
bcf6a23fa0

+ 11 - 0
.changeset/itchy-falcons-doubt.md

@@ -0,0 +1,11 @@
+---
+"@kinobi-so/renderers-js-umi": patch
+"@kinobi-so/renderers-core": patch
+"@kinobi-so/renderers-rust": patch
+"@kinobi-so/renderers-js": patch
+"kinobi": patch
+"@kinobi-so/errors": patch
+"@kinobi-so/nodes": patch
+---
+
+Replace \_\_DEV\_\_ with NODE_ENV is not production in Kinobi

+ 1 - 1
packages/errors/src/message-formatter.ts

@@ -19,7 +19,7 @@ export function getHumanReadableErrorMessage<TErrorCode extends KinobiErrorCode>
 }
 
 export function getErrorMessage<TErrorCode extends KinobiErrorCode>(code: TErrorCode, context: object = {}): string {
-    if (__DEV__) {
+    if (process.env.NODE_ENV !== 'production') {
         return getHumanReadableErrorMessage(code, context);
     } else {
         let decodingAdviceMessage = `Kinobi error #${code}; Decode this error by running \`npx @kinobi-so/errors decode -- ${code}`;

+ 0 - 1
packages/errors/src/types/global.d.ts

@@ -1,5 +1,4 @@
 declare const __BROWSER__: boolean;
-declare const __DEV__: boolean;
 declare const __ESM__: boolean;
 declare const __NODEJS__: boolean;
 declare const __REACTNATIVE__: boolean;

+ 0 - 1
packages/errors/test/types/global.d.ts

@@ -1,5 +1,4 @@
 declare const __BROWSER__: boolean;
-declare const __DEV__: boolean;
 declare const __ESM__: boolean;
 declare const __NODEJS__: boolean;
 declare const __REACTNATIVE__: boolean;

+ 0 - 3
packages/internals/env-shim.ts

@@ -1,3 +0,0 @@
-// Clever obfuscation to prevent the build system from inlining the value of `NODE_ENV`
-export const __DEV__ = /* @__PURE__ */ (() =>
-    (process as any)['en' + 'v'].NODE_ENV === 'development' || (process as any)['en' + 'v'].NODE_ENV === 'test')();

+ 5 - 3
packages/internals/tsup.config.base.ts

@@ -1,4 +1,3 @@
-import path from 'node:path';
 import { env } from 'node:process';
 
 import browsersListToEsBuild from 'browserslist-to-esbuild';
@@ -26,11 +25,14 @@ export function getBuildConfig(options: BuildOptions): TsupConfig {
         },
         entry: [`./src/index.ts`],
         esbuildOptions(options, context) {
-            options.inject = [path.resolve(__dirname, 'env-shim.ts')];
             if (context.format === 'iife') {
-                options.define = { ...options.define, __DEV__: `false` };
                 options.target = BROWSERSLIST_TARGETS;
                 options.minify = true;
+            } else {
+                options.define = {
+                    ...options.define,
+                    'process.env.NODE_ENV': 'process.env.NODE_ENV',
+                };
             }
         },
         external: ['node:fs', 'node:path', 'node:url'],

+ 0 - 1
packages/internals/vitest.config.base.mts

@@ -8,7 +8,6 @@ export function getVitestConfig(platform: Platform) {
     return defineConfig({
         define: {
             __BROWSER__: `${platform === 'browser'}`,
-            __DEV__: 'true',
             __ESM__: 'true',
             __NODEJS__: `${platform === 'node'}`,
             __REACTNATIVE__: `${platform === 'react-native'}`,

+ 0 - 1
packages/library/src/types/global.d.ts

@@ -1,5 +1,4 @@
 declare const __BROWSER__: boolean;
-declare const __DEV__: boolean;
 declare const __ESM__: boolean;
 declare const __NODEJS__: boolean;
 declare const __REACTNATIVE__: boolean;

+ 0 - 1
packages/nodes/src/types/global.d.ts

@@ -1,5 +1,4 @@
 declare const __BROWSER__: boolean;
-declare const __DEV__: boolean;
 declare const __ESM__: boolean;
 declare const __NODEJS__: boolean;
 declare const __REACTNATIVE__: boolean;

+ 0 - 1
packages/nodes/test/types/global.d.ts

@@ -1,5 +1,4 @@
 declare const __BROWSER__: boolean;
-declare const __DEV__: boolean;
 declare const __ESM__: boolean;
 declare const __NODEJS__: boolean;
 declare const __REACTNATIVE__: boolean;

+ 0 - 1
packages/renderers-core/src/types/global.d.ts

@@ -1,5 +1,4 @@
 declare const __BROWSER__: boolean;
-declare const __DEV__: boolean;
 declare const __ESM__: boolean;
 declare const __NODEJS__: boolean;
 declare const __REACTNATIVE__: boolean;

+ 0 - 1
packages/renderers-core/test/types/global.d.ts

@@ -1,5 +1,4 @@
 declare const __BROWSER__: boolean;
-declare const __DEV__: boolean;
 declare const __ESM__: boolean;
 declare const __NODEJS__: boolean;
 declare const __REACTNATIVE__: boolean;

+ 0 - 1
packages/renderers-js-umi/src/types/global.d.ts

@@ -1,5 +1,4 @@
 declare const __BROWSER__: boolean;
-declare const __DEV__: boolean;
 declare const __ESM__: boolean;
 declare const __NODEJS__: boolean;
 declare const __REACTNATIVE__: boolean;

+ 0 - 1
packages/renderers-js/src/types/global.d.ts

@@ -1,5 +1,4 @@
 declare const __BROWSER__: boolean;
-declare const __DEV__: boolean;
 declare const __ESM__: boolean;
 declare const __NODEJS__: boolean;
 declare const __REACTNATIVE__: boolean;

+ 0 - 1
packages/renderers-rust/src/types/global.d.ts

@@ -1,5 +1,4 @@
 declare const __BROWSER__: boolean;
-declare const __DEV__: boolean;
 declare const __ESM__: boolean;
 declare const __NODEJS__: boolean;
 declare const __REACTNATIVE__: boolean;

+ 1 - 0
turbo.json

@@ -1,5 +1,6 @@
 {
     "$schema": "https://turbo.build/schema.json",
+    "globalEnv": ["NODE_ENV"],
     "pipeline": {
         "build": {
             "dependsOn": ["^build"]