rajt 0.0.54 → 0.0.55

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rajt",
3
3
  "description": "A serverless bundler layer, fully typed for AWS Lambda (Node.js and LLRT) and Cloudflare Workers.",
4
- "version": "0.0.54",
4
+ "version": "0.0.55",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "exports": {
package/src/dev.ts CHANGED
@@ -6,6 +6,9 @@ import { registerHandler, registerMiddleware } from './register'
6
6
  import { Ability } from './auth'
7
7
  import { getAvailablePort } from './utils/port'
8
8
  import jsonImport from './utils/json-import'
9
+ import { setEnv, detectEnvironment } from './utils/environment'
10
+
11
+ setEnv(detectEnvironment())
9
12
 
10
13
  config({ path: '../../.env.dev' })
11
14
 
@@ -1,19 +1,33 @@
1
- export default function getEnvironment() {
1
+ const prd = Symbol('prd')
2
+ const dev = Symbol('dev')
3
+
4
+ let env = prd
5
+
6
+ export const getEnv = () => env
7
+ export const setEnv = (e: symbol) => env = e
8
+
9
+ export function detectEnvironment() {
2
10
  try {
3
11
  if (
4
- process.env?.npm_lifecycle_event === 'dev'
12
+ process.env?.npm_lifecycle_event == 'dev'
5
13
  || process.env?.AWS_SAM_LOCAL
6
- || process?.argv?.includes('--dev')
14
+ // || process?.argv?.includes('--dev')
15
+ || process?.argv?.some(arg => ['--dev', '--development', '--watch'].includes(arg))
7
16
  || process?.execArgv?.includes('--watch')
8
17
  || import.meta.url?.includes('localhost')
9
18
  ) {
10
- return 'dev'
19
+ return dev
11
20
  }
12
21
  } catch (e) { }
13
22
 
14
- return 'prod'
23
+ return prd
15
24
  }
16
25
 
17
- export const isDev = () => getEnvironment() === 'dev'
18
- export const isProd = () => getEnvironment() === 'prod'
26
+ export const isEnv = (e: symbol) => env == e
27
+
28
+ export const isDev = () => env == dev
29
+ export const isProd = () => env == prd
30
+
31
+ export const isDevelopment = isDev
32
+ export const isProduction = isProd
19
33
  export const isPrd = isProd