Эх сурвалжийг харах

Replace __DEV__ with NODE_ENV is not production in JS renderer (#103)

Loris Leiva 1 жил өмнө
parent
commit
93942ccb8c

+ 5 - 0
.changeset/nice-cheetahs-punch.md

@@ -0,0 +1,5 @@
+---
+"@kinobi-so/renderers-js": patch
+---
+
+Replace \_\_DEV\_\_ with NODE_ENV is not production in generated code

+ 3 - 3
packages/renderers-js/e2e/anchor/src/generated/errors/wenTransferGuard.ts

@@ -36,7 +36,7 @@ export type WenTransferGuardError =
 let wenTransferGuardErrorMessages:
   | Record<WenTransferGuardError, string>
   | undefined;
-if (__DEV__) {
+if (process.env.NODE_ENV !== 'production') {
   wenTransferGuardErrorMessages = {
     [WEN_TRANSFER_GUARD_ERROR__CPI_RULE_ENFORCEMENT_FAILED]: `Cpi Rule Enforcement Failed`,
     [WEN_TRANSFER_GUARD_ERROR__GUARD_TOKEN_AMOUNT_SHOULD_BE_AT_LEAST_ONE]: `Guard token amount should be at least 1`,
@@ -52,11 +52,11 @@ if (__DEV__) {
 export function getWenTransferGuardErrorMessage(
   code: WenTransferGuardError
 ): string {
-  if (__DEV__) {
+  if (process.env.NODE_ENV !== 'production') {
     return (
       wenTransferGuardErrorMessages as Record<WenTransferGuardError, string>
     )[code];
   }
 
-  return 'Error message not available in production bundles. Compile with `__DEV__` set to true to see more information.';
+  return 'Error message not available in production bundles.';
 }

+ 0 - 11
packages/renderers-js/e2e/anchor/src/generated/global.d.ts

@@ -1,11 +0,0 @@
-/**
- * This code was AUTOGENERATED using the kinobi library.
- * Please DO NOT EDIT THIS FILE, instead use visitors
- * to add features, then rerun kinobi to update it.
- *
- * @see https://github.com/kinobi-so/kinobi
- */
-
-/** Global variable provided by bundlers telling us if we are building for production or not. */
-// eslint-disable-next-line @typescript-eslint/naming-convention
-declare const __DEV__: boolean;

+ 0 - 11
packages/renderers-js/e2e/memo/src/generated/global.d.ts

@@ -1,11 +0,0 @@
-/**
- * This code was AUTOGENERATED using the kinobi library.
- * Please DO NOT EDIT THIS FILE, instead use visitors
- * to add features, then rerun kinobi to update it.
- *
- * @see https://github.com/kinobi-so/kinobi
- */
-
-/** Global variable provided by bundlers telling us if we are building for production or not. */
-// eslint-disable-next-line @typescript-eslint/naming-convention
-declare const __DEV__: boolean;

+ 3 - 3
packages/renderers-js/e2e/system/src/generated/errors/system.ts

@@ -37,7 +37,7 @@ export type SystemError =
   | typeof SYSTEM_ERROR__RESULT_WITH_NEGATIVE_LAMPORTS;
 
 let systemErrorMessages: Record<SystemError, string> | undefined;
-if (__DEV__) {
+if (process.env.NODE_ENV !== 'production') {
   systemErrorMessages = {
     [SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE]: `an account with the same address already exists`,
     [SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH]: `provided address does not match addressed derived from seed`,
@@ -52,9 +52,9 @@ if (__DEV__) {
 }
 
 export function getSystemErrorMessage(code: SystemError): string {
-  if (__DEV__) {
+  if (process.env.NODE_ENV !== 'production') {
     return (systemErrorMessages as Record<SystemError, string>)[code];
   }
 
-  return 'Error message not available in production bundles. Compile with `__DEV__` set to true to see more information.';
+  return 'Error message not available in production bundles.';
 }

+ 0 - 11
packages/renderers-js/e2e/system/src/generated/global.d.ts

@@ -1,11 +0,0 @@
-/**
- * This code was AUTOGENERATED using the kinobi library.
- * Please DO NOT EDIT THIS FILE, instead use visitors
- * to add features, then rerun kinobi to update it.
- *
- * @see https://github.com/kinobi-so/kinobi
- */
-
-/** Global variable provided by bundlers telling us if we are building for production or not. */
-// eslint-disable-next-line @typescript-eslint/naming-convention
-declare const __DEV__: boolean;

+ 3 - 3
packages/renderers-js/e2e/token/src/generated/errors/associatedToken.ts

@@ -14,7 +14,7 @@ export type AssociatedTokenError = typeof ASSOCIATED_TOKEN_ERROR__INVALID_OWNER;
 let associatedTokenErrorMessages:
   | Record<AssociatedTokenError, string>
   | undefined;
-if (__DEV__) {
+if (process.env.NODE_ENV !== 'production') {
   associatedTokenErrorMessages = {
     [ASSOCIATED_TOKEN_ERROR__INVALID_OWNER]: `Associated token account owner does not match address derivation`,
   };
@@ -23,11 +23,11 @@ if (__DEV__) {
 export function getAssociatedTokenErrorMessage(
   code: AssociatedTokenError
 ): string {
-  if (__DEV__) {
+  if (process.env.NODE_ENV !== 'production') {
     return (
       associatedTokenErrorMessages as Record<AssociatedTokenError, string>
     )[code];
   }
 
-  return 'Error message not available in production bundles. Compile with `__DEV__` set to true to see more information.';
+  return 'Error message not available in production bundles.';
 }

+ 3 - 3
packages/renderers-js/e2e/token/src/generated/errors/token.ts

@@ -70,7 +70,7 @@ export type TokenError =
   | typeof TOKEN_ERROR__UNINITIALIZED_STATE;
 
 let tokenErrorMessages: Record<TokenError, string> | undefined;
-if (__DEV__) {
+if (process.env.NODE_ENV !== 'production') {
   tokenErrorMessages = {
     [TOKEN_ERROR__ACCOUNT_FROZEN]: `Account is frozen`,
     [TOKEN_ERROR__ALREADY_IN_USE]: `Already in use`,
@@ -96,9 +96,9 @@ if (__DEV__) {
 }
 
 export function getTokenErrorMessage(code: TokenError): string {
-  if (__DEV__) {
+  if (process.env.NODE_ENV !== 'production') {
     return (tokenErrorMessages as Record<TokenError, string>)[code];
   }
 
-  return 'Error message not available in production bundles. Compile with `__DEV__` set to true to see more information.';
+  return 'Error message not available in production bundles.';
 }

+ 0 - 11
packages/renderers-js/e2e/token/src/generated/global.d.ts

@@ -1,11 +0,0 @@
-/**
- * This code was AUTOGENERATED using the kinobi library.
- * Please DO NOT EDIT THIS FILE, instead use visitors
- * to add features, then rerun kinobi to update it.
- *
- * @see https://github.com/kinobi-so/kinobi
- */
-
-/** Global variable provided by bundlers telling us if we are building for production or not. */
-// eslint-disable-next-line @typescript-eslint/naming-convention
-declare const __DEV__: boolean;

+ 3 - 3
packages/renderers-js/public/templates/fragments/programErrors.njk

@@ -11,7 +11,7 @@ export type {{ programErrorUnion }} =
   {% endfor %};
 
 let {{ programErrorMessagesMap }}: Record<{{ programErrorUnion }}, string> | undefined;
-if (__DEV__) {
+if (process.env.NODE_ENV !== 'production') {
   {{ programErrorMessagesMap }} = {
     {% for error in errors | sort(false, false, 'name') %}
       [{{ getProgramErrorConstant(error.name) }}]: `{{ error.message }}`,
@@ -20,9 +20,9 @@ if (__DEV__) {
 }
 
 export function {{ programGetErrorMessageFunction }}(code: {{ programErrorUnion }}): string {
-  if (__DEV__) {
+  if (process.env.NODE_ENV !== 'production') {
     return ({{ programErrorMessagesMap }} as Record<{{ programErrorUnion }}, string>)[code];
   }
 
-  return 'Error message not available in production bundles. Compile with `__DEV__` set to true to see more information.';
+  return 'Error message not available in production bundles.';
 }

+ 0 - 7
packages/renderers-js/public/templates/pages/globalTypesPage.njk

@@ -1,7 +0,0 @@
-{% extends "layout.njk" %}
-
-{% block main %}
-/** Global variable provided by bundlers telling us if we are building for production or not. */
-// eslint-disable-next-line @typescript-eslint/naming-convention
-declare const __DEV__: boolean;
-{% endblock %}

+ 0 - 1
packages/renderers-js/src/getRenderMapVisitor.ts

@@ -406,7 +406,6 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) {
 
                     return map
                         .add('index.ts', render('rootIndex.njk', ctx))
-                        .add('global.d.ts', render('globalTypesPage.njk', ctx))
                         .mergeWith(...getAllPrograms(node).map(p => visit(p, self)));
                 },
             }),