piral-cli 1.12.2 → 1.12.3-beta.8ac5696

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.
@@ -71569,12 +71569,20 @@ rimraf.rimraf = rimraf;
71569
71569
  var fs2 = __toESM(require_graceful_fs());
71570
71570
  var import_enhanced_resolve = __toESM(require_lib5());
71571
71571
  var nodeFileSystem = new import_enhanced_resolve.CachedInputFileSystem(fs2, 100);
71572
+ var isProduction = process.env.NODE_ENV === "production";
71572
71573
  var nodeContext = {
71573
71574
  environments: ["node+es3+es5+process+native"]
71574
71575
  };
71575
71576
  var enhancedResolve = import_enhanced_resolve.ResolverFactory.createResolver({
71576
71577
  aliasFields: ["browser"],
71577
- conditionNames: ["import", "module", "webpack", "development", "browser"],
71578
+ conditionNames: [
71579
+ "import",
71580
+ "module",
71581
+ "webpack",
71582
+ ...isProduction ? ["default"] : ["development"],
71583
+ "browser",
71584
+ "default"
71585
+ ],
71578
71586
  extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".json"],
71579
71587
  exportsFields: ["exports"],
71580
71588
  importsFields: ["imports"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-cli",
3
- "version": "1.12.2",
3
+ "version": "1.12.3-beta.8ac5696",
4
4
  "description": "The standard CLI for creating and building a Piral instance or a Pilet.",
5
5
  "keywords": [
6
6
  "portal",
@@ -0,0 +1,57 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ async function loadResolver(nodeEnv: string | undefined) {
4
+ vi.resetModules();
5
+
6
+ const resolveSync = vi.fn(() => '/resolved/module');
7
+ let resolverOptions: any;
8
+ const cachedInputFileSystemCtor = vi.fn();
9
+
10
+ vi.doMock('enhanced-resolve', () => ({
11
+ ResolverFactory: {
12
+ createResolver: (options: any) => {
13
+ resolverOptions = options;
14
+ return {
15
+ resolveSync,
16
+ };
17
+ },
18
+ },
19
+ CachedInputFileSystem: class MockCachedInputFileSystem {
20
+ constructor(fs: any, duration: number) {
21
+ cachedInputFileSystemCtor(fs, duration);
22
+ }
23
+ },
24
+ }));
25
+
26
+ vi.unstubAllEnvs();
27
+ vi.stubEnv('NODE_ENV', nodeEnv ?? '');
28
+
29
+ const module = await import('./resolve');
30
+
31
+ return { ...module, resolveSync, resolverOptions, cachedInputFileSystemCtor };
32
+ }
33
+
34
+ describe('resolve module', () => {
35
+ afterEach(() => {
36
+ vi.unstubAllEnvs();
37
+ vi.resetModules();
38
+ vi.clearAllMocks();
39
+ });
40
+
41
+ it('uses development conditions outside production', async () => {
42
+ const { getModulePath, resolverOptions, cachedInputFileSystemCtor } = await loadResolver('development');
43
+
44
+ expect(cachedInputFileSystemCtor).toHaveBeenCalledOnce();
45
+ expect(resolverOptions.conditionNames).toContain('development');
46
+ expect(getModulePath('/root', 'pkg')).toBe('/resolved/module');
47
+ });
48
+
49
+ it('uses default conditions in production', async () => {
50
+ const { getModulePath, resolverOptions, cachedInputFileSystemCtor } = await loadResolver('production');
51
+
52
+ expect(cachedInputFileSystemCtor).toHaveBeenCalledOnce();
53
+ expect(resolverOptions.conditionNames).toContain('default');
54
+ expect(resolverOptions.conditionNames).not.toContain('development');
55
+ expect(getModulePath('/root', 'pkg')).toBe('/resolved/module');
56
+ });
57
+ });
@@ -2,6 +2,7 @@ import * as fs from 'graceful-fs';
2
2
  import { ResolverFactory, CachedInputFileSystem } from 'enhanced-resolve';
3
3
 
4
4
  const nodeFileSystem = new CachedInputFileSystem(fs, 100);
5
+ const isProduction = process.env.NODE_ENV === 'production';
5
6
 
6
7
  const nodeContext = {
7
8
  environments: ['node+es3+es5+process+native'],
@@ -9,7 +10,14 @@ const nodeContext = {
9
10
 
10
11
  const enhancedResolve = ResolverFactory.createResolver({
11
12
  aliasFields: ['browser'],
12
- conditionNames: ['import', 'module', 'webpack', 'development', 'browser'],
13
+ conditionNames: [
14
+ 'import',
15
+ 'module',
16
+ 'webpack',
17
+ ...(isProduction ? ['default'] : ['development']),
18
+ 'browser',
19
+ 'default',
20
+ ],
13
21
  extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.json'],
14
22
  exportsFields: ['exports'],
15
23
  importsFields: ['imports'],