Skip to content

Commit 5d8241c

Browse files
committed
Add resources url
1 parent 02f6e5d commit 5d8241c

File tree

4 files changed

+62
-39
lines changed

4 files changed

+62
-39
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"copy-examples": "node utils/copy-examples",
8181
"release:ci": "rm -rf dist && npm run build:all && $NPM_TOKEN=%env.NPM_TOKEN% npm publish",
8282
"start": "webpack-dev-server --port 9002",
83-
"start-with-local-compiler": "webpack-dev-server --port 9002 --env webDemoUrl='//localhost:8080'",
83+
"start-with-local-compiler": "webpack-dev-server --port 9002 --env webDemoUrl='//localhost:8080' webDemoResourcesUrl='//localhost:8081'",
8484
"lint": "eslint . --ext .ts",
8585
"fix": "eslint --fix --ext .ts .",
8686
"test": "npm run build:all && npm run test:run",

src/config.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export const RUNTIME_CONFIG = { ...getConfigFromElement(currentScript) };
1313
export const API_URLS = {
1414
server: (RUNTIME_CONFIG.server || __WEBDEMO_URL__).replace(/\/$/, ''),
1515
composeServer: (
16-
__WEBDEMO_URL__
16+
__WEBDEMO_URL__ || 'https://compose.sandbox.intellij.net'
17+
).replace(/\/$/, ''),
18+
composeResources: (
19+
__WEBDEMO_RESOURCES_URL__ || 'https://compose.sandbox.intellij.net'
1720
).replace(/\/$/, ''),
1821

1922
COMPILE(platform, version) {
@@ -62,17 +65,23 @@ export const API_URLS = {
6265
get VERSIONS() {
6366
return `${this.server}/versions`;
6467
},
68+
SKIKO_VERSION() {
69+
return `${this.composeServer}/api/resource/skiko`;
70+
},
6571
SKIKO_MJS(version) {
66-
return `${this.composeServer}/api/resource/skiko.mjs`;
72+
return `${this.composeResources}/api/resource/skiko-${version}.mjs`;
6773
},
6874
SKIKO_WASM(version) {
69-
return `${this.composeServer}/api/resource/skiko.wasm`;
75+
return `${this.composeResources}/api/resource/skiko-${version}.wasm`;
76+
},
77+
STDLIB_HASH() {
78+
return `${this.composeServer}/api/resource/stdlib`;
7079
},
71-
STDLIB_MJS(version) {
72-
return `${this.composeServer}/api/resource/stdlib.mjs`;
80+
STDLIB_MJS(hash) {
81+
return `${this.composeResources}/api/resource/stdlib-${hash}.mjs`;
7382
},
74-
STDLIB_WASM(version) {
75-
return `${this.composeServer}/api/resource/stdlib.wasm`;
83+
STDLIB_WASM(hash) {
84+
return `${this.composeResources}/api/resource/stdlib-${hash}.wasm`;
7685
},
7786
get JQUERY() {
7887
return `https://cdn.jsdelivr.net/npm/jquery@1/dist/jquery.min.js`;

src/js-executor/index.js

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -183,38 +183,50 @@ export default class JsExecutor {
183183
}
184184
if (targetPlatform === TargetPlatforms.COMPOSE_WASM) {
185185

186-
const skikoExports = fetch(API_URLS.SKIKO_MJS(compilerVersion), {
187-
method: 'GET',
188-
headers: {
189-
'Content-Type': 'text/javascript',
190-
}
191-
}).then(script => script.text())
192-
.then(script => script.replace(
193-
"new URL(\"skiko.wasm\",import.meta.url).href",
194-
`'${API_URLS.SKIKO_WASM(compilerVersion)}'`
195-
))
196-
.then(async skikoCode =>
197-
executeJs(
198-
this.iframe.contentWindow,
199-
skikoCode,
200-
))
201-
.then(skikoExports => fixedSkikoExports(skikoExports))
186+
const skikoExports = fetch(API_URLS.SKIKO_VERSION(), {
187+
method: 'GET'
188+
}).then(response => response.text())
189+
.then(version =>
190+
fetch(API_URLS.SKIKO_MJS(version), {
191+
method: 'GET',
192+
headers: {
193+
'Content-Type': 'text/javascript',
194+
}
195+
}).then(script => script.text())
196+
.then(script => script.replace(
197+
"new URL(\"skiko.wasm\",import.meta.url).href",
198+
`'${API_URLS.SKIKO_WASM(version)}'`
199+
))
200+
.then(async skikoCode =>
201+
executeJs(
202+
this.iframe.contentWindow,
203+
skikoCode,
204+
))
205+
.then(skikoExports => fixedSkikoExports(skikoExports)))
202206

203-
const stdlibExports = fetch(API_URLS.STDLIB_MJS(compilerVersion), {
204-
method: 'GET',
205-
headers: {
206-
'Content-Type': 'text/javascript',
207-
}
208-
}).then(script => script.text())
209-
.then(script => script.replace(
210-
"new URL('./stdlib.wasm',import.meta.url).href",
211-
`'${API_URLS.STDLIB_WASM(compilerVersion)}'`
212-
))
213-
.then(stdlibCode =>
214-
executeWasmCodeWithSkiko(
215-
this.iframe.contentWindow,
216-
stdlibCode,
217-
)
207+
const stdlibExports = fetch(API_URLS.STDLIB_HASH(), {
208+
method: 'GET'
209+
}).then(response => response.text())
210+
.then(hash =>
211+
fetch(API_URLS.STDLIB_MJS(hash), {
212+
method: 'GET',
213+
headers: {
214+
'Content-Type': 'text/javascript',
215+
}
216+
}).then(script => script.text())
217+
.then(script => script.replace(
218+
"new URL('./stdlib.wasm',import.meta.url).href",
219+
`'${API_URLS.STDLIB_WASM(hash)}'`
220+
).replace(
221+
"(extends) => { return { extends }; }",
222+
"(extends_) => { return { extends_ }; }"
223+
))
224+
.then(stdlibCode =>
225+
executeWasmCodeWithSkiko(
226+
this.iframe.contentWindow,
227+
stdlibCode,
228+
)
229+
)
218230
)
219231

220232
this.stdlibExports = Promise.all([skikoExports, stdlibExports])

webpack.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = (params = {}) => {
99
const isServer = process.argv[1].includes('webpack-dev-server');
1010
const libraryName = 'KotlinPlayground';
1111
const webDemoUrl = params.webDemoUrl || 'https://api.kotlinlang.org/';
12+
const webDemoResourcesUrl = params.webDemoResourcesUrl || 'https://api.kotlinlang.org/';
1213
const examplesPath = isServer ? '' : 'examples/';
1314
const pathDist = path.resolve(__dirname, 'dist');
1415

@@ -98,6 +99,7 @@ module.exports = (params = {}) => {
9899

99100
new webpack.DefinePlugin({
100101
__WEBDEMO_URL__: JSON.stringify(webDemoUrl),
102+
__WEBDEMO_RESOURCES_URL__: JSON.stringify(webDemoResourcesUrl),
101103
__IS_PRODUCTION__: isProduction,
102104
__LIBRARY_NAME__: JSON.stringify(libraryName),
103105
}),

0 commit comments

Comments
 (0)