Skip to content

Commit 60fb8f9

Browse files
authored
Retain loader specification when downloading asynchronous dependency (codesandbox#1796)
* Retain loader specification when downloading asynchronous dependency Fixes codesandbox#1784 * Fix integration test by adding right docker image
1 parent 9d76691 commit 60fb8f9

File tree

4 files changed

+54
-35
lines changed

4 files changed

+54
-35
lines changed

.circleci/config.yml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ version: 2.1
77
aliases:
88
- &restore_repo_cache
99
key: v17-repo-{{ .Environment.CIRCLE_SHA1 }}
10-
10+
1111
- &save_repo_cache
1212
key: v17-repo-{{ .Environment.CIRCLE_SHA1 }}
1313
paths:
1414
- ~/codesandbox-client
15-
15+
1616
- &restore_deps_cache
1717
keys:
1818
- v17-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
1919
- v17-dependency-cache-{{ .Branch }}
2020
- v17-dependency-cache
21-
21+
2222
- &save_deps_cache
2323
key: v17-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
2424
paths:
@@ -41,15 +41,15 @@ aliases:
4141
- v17-standalone-dependency-cache-{{ .Branch }}-{{ checksum "standalone-packages/codesandbox-browserfs/yarn.lock" }}
4242
- v17-standalone-dependency-cache-{{ .Branch }}
4343
- v17-standalone-dependency-cache
44-
44+
4545
- &save_standalone_deps_cache
4646
key: v17-standalone-dependency-cache-{{ .Branch }}-{{ checksum "standalone-packages/codesandbox-browserfs/yarn.lock" }}
4747
paths:
4848
- standalone-packages/codesandbox-browserfs/node_modules
49-
49+
5050
- &restore_prod_build_cache
5151
key: v17-prod-app-build-cache-master
52-
52+
5353
- &restore_prod_cache
5454
key: v17-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
5555

@@ -58,15 +58,15 @@ aliases:
5858
paths:
5959
- ./packages/app/www
6060
- ./packages/app/.cache-loader
61-
61+
6262
- &save_prod_cache
6363
key: v17-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
6464
paths:
6565
- ./www
66-
66+
6767
- &store_test_results
6868
path: /tmp/test-results
69-
69+
7070
- &store_artifacts
7171
path: packages/app/integration-tests/tests/__image_snapshots__/__diff_output__
7272
destination: image_snapshot_diff
@@ -80,6 +80,10 @@ executors:
8080
docker:
8181
- image: circleci/node:10
8282
working_directory: ~/codesandbox-client
83+
node-with-puppeteer:
84+
docker:
85+
- image: codesandbox/node-puppeteer
86+
working_directory: ~/codesandbox-client
8387
docker_machine:
8488
machine: true
8589
working_directory: ~/codesandbox-client
@@ -90,7 +94,7 @@ executors:
9094

9195
commands:
9296
build_deps:
93-
description: "Install Dependencies with `yarn install`"
97+
description: 'Install Dependencies with `yarn install`'
9498
steps:
9599
- restore_cache: *restore_deps_cache
96100
- restore_cache: *restore_standalone_deps_cache
@@ -104,7 +108,7 @@ commands:
104108
command: yarn build:deps
105109
- save_cache: *save_repo_cache
106110
build_prod:
107-
description: "Build the Application with `yarn build:prod`"
111+
description: 'Build the Application with `yarn build:prod`'
108112
steps:
109113
- restore_cache: *restore_repo_cache
110114
- restore_cache: *restore_prod_build_cache
@@ -135,7 +139,7 @@ commands:
135139
- store_test_results: *store_test_results
136140
- store_artifacts: *store_artifacts
137141
test_jest:
138-
description: "Test with `yarn test`"
142+
description: 'Test with `yarn test`'
139143
steps:
140144
- restore_cache: *restore_repo_cache
141145
- run:
@@ -144,28 +148,28 @@ commands:
144148
environment:
145149
JEST_JUNIT_OUTPUT: 'reports/junit/js-tests-results.xml'
146150
yarn_lint:
147-
description: "Lint with `yarn lint`"
151+
description: 'Lint with `yarn lint`'
148152
steps:
149153
- restore_cache: *restore_repo_cache
150154
- run:
151155
name: Lint
152156
command: yarn lint
153157
yarn_typecheck:
154-
description: "Lint with `yarn typecheck`"
158+
description: 'Lint with `yarn typecheck`'
155159
steps:
156160
- restore_cache: *restore_repo_cache
157161
- run:
158162
name: Lint
159163
command: yarn typecheck
160164
docker_cache:
161-
description: "Cache, Sign In, Create, and Push Docker Image"
165+
description: 'Cache, Sign In, Create, and Push Docker Image'
162166
parameters:
163167
user:
164168
type: string
165-
default: "$DOCKER_USER"
169+
default: '$DOCKER_USER'
166170
password:
167171
type: string
168-
default: "$DOCKER_PWD"
172+
default: '$DOCKER_PWD'
169173
steps:
170174
- restore_cache: *restore_prod_cache
171175
- run:
@@ -194,7 +198,7 @@ jobs:
194198
- checkout
195199
- build_prod
196200
test-integrations:
197-
executor: node
201+
executor: node-with-puppeteer
198202
steps:
199203
- checkout
200204
- test_integrations

packages/app/src/sandbox/eval/manager.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { ignoreNextCache, deleteAPICache, clearIndexedDBCache } from './cache';
2626
import { shouldTranspile } from './transpilers/babel/check';
2727
import { getGlobal } from '@codesandbox/common/lib/utils/global';
2828
import { ParsedConfigurationFiles } from '@codesandbox/common/lib/templates/template';
29+
import { splitQueryFromPath } from './utils/query-path';
2930

3031
declare var BrowserFS: any;
3132

@@ -761,10 +762,11 @@ export default class Manager {
761762
downloadDependency(
762763
path: string,
763764
currentTModule: TranspiledModule,
765+
query: string = '',
764766
ignoredExtensions: Array<string> = this.preset.ignoredExtensions
765767
): Promise<TranspiledModule> {
766768
return fetchModule(path, currentTModule, this, ignoredExtensions).then(
767-
module => this.getTranspiledModule(module)
769+
module => this.getTranspiledModule(module, query)
768770
);
769771
}
770772

@@ -794,7 +796,13 @@ export default class Manager {
794796
);
795797
} catch (e) {
796798
if (e.type === 'module-not-found' && e.isDependency) {
797-
return this.downloadDependency(e.path, tModule, ignoredExtensions);
799+
const { queryPath } = splitQueryFromPath(path);
800+
return this.downloadDependency(
801+
e.path,
802+
tModule,
803+
queryPath,
804+
ignoredExtensions
805+
);
798806
}
799807

800808
throw e;
@@ -844,16 +852,14 @@ export default class Manager {
844852
throw new Error('Cannot resolve webpack path');
845853
}
846854

847-
const queryPath = path.split('!');
848-
// pop() mutates queryPath, queryPath is now just the loaders
849-
const modulePath = queryPath.pop();
855+
const { queryPath, modulePath } = splitQueryFromPath(path);
850856

851857
if (async) {
852858
return this.resolveModuleAsync(
853859
modulePath,
854860
currentPath,
855861
ignoredExtensions || this.preset.ignoredExtensions
856-
).then(module => this.getTranspiledModule(module, queryPath.join('!')));
862+
).then(module => this.getTranspiledModule(module, queryPath));
857863
}
858864

859865
const module = this.resolveModule(
@@ -862,29 +868,24 @@ export default class Manager {
862868
ignoredExtensions || this.preset.ignoredExtensions
863869
);
864870

865-
return this.getTranspiledModule(module, queryPath.join('!'));
871+
return this.getTranspiledModule(module, queryPath);
866872
}
867873

868874
resolveTranspiledModulesInDirectory(
869875
path: string,
870876
currentPath: string
871877
): Array<TranspiledModule> {
872-
const queryPath = path.split('!');
873-
// pop() mutates queryPath, queryPath is now just the loaders
874-
const modulesPath = queryPath.pop();
878+
const { queryPath, modulePath } = splitQueryFromPath(path);
875879

876880
const joinedPath = pathUtils.join(
877881
pathUtils.dirname(currentPath),
878-
modulesPath
882+
modulePath
879883
);
880884

881885
return Object.keys(this.transpiledModules)
882886
.filter(p => p.startsWith(joinedPath))
883887
.map(m =>
884-
this.getTranspiledModule(
885-
this.transpiledModules[m].module,
886-
queryPath.join('!')
887-
)
888+
this.getTranspiledModule(this.transpiledModules[m].module, queryPath)
888889
);
889890
}
890891

packages/app/src/sandbox/eval/transpiled-module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import evaluate from './loaders/eval';
1919

2020
import Manager, { HMRStatus } from './manager';
2121
import HMR from './hmr';
22+
import { splitQueryFromPath } from './utils/query-path';
2223

2324
declare var BrowserFS: any;
2425

@@ -352,7 +353,10 @@ export default class TranspiledModule {
352353
}
353354
} catch (e) {
354355
if (e.type === 'module-not-found' && e.isDependency) {
355-
this.asyncDependencies.push(manager.downloadDependency(e.path, this));
356+
const { queryPath } = splitQueryFromPath(depPath);
357+
this.asyncDependencies.push(
358+
manager.downloadDependency(e.path, this, queryPath)
359+
);
356360
} else {
357361
// When a custom file resolver is given to the manager we will try
358362
// to resolve using this file resolver. If that fails we will still
@@ -593,7 +597,7 @@ export default class TranspiledModule {
593597
let finalSourceMap = null;
594598

595599
const requires = this.module.requires;
596-
if (requires != null) {
600+
if (requires != null && this.query === '') {
597601
// We now know that this has been transpiled on the server, so we shortcut
598602
const loaderContext = this.getLoaderContext(manager, {});
599603
// These are precomputed requires, for npm dependencies
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const splitQueryFromPath = (path: string) => {
2+
const queryPath = path.split('!');
3+
// pop() mutates queryPath, queryPath is now just the loaders
4+
const modulePath = queryPath.pop();
5+
6+
return {
7+
queryPath: queryPath.join('!'),
8+
modulePath,
9+
};
10+
};

0 commit comments

Comments
 (0)