trying to find why dynamic module loading isn't working.
This commit is contained in:
parent
75ad94421d
commit
de009f04d4
|
@ -29,7 +29,8 @@
|
|||
(prefix-in resource-query: "../resource/query.rkt")
|
||||
(prefix-in runtime: "get-runtime.rkt")
|
||||
(prefix-in racket: racket/base)
|
||||
racket/runtime-path)
|
||||
racket/runtime-path
|
||||
json)
|
||||
|
||||
|
||||
|
||||
|
@ -597,7 +598,8 @@ EOF
|
|||
(define (get-html-template js-files
|
||||
#:manifest (manifest #f)
|
||||
#:with-legacy-ie-support? (with-legacy-ie-support? #t)
|
||||
#:title (title ""))
|
||||
#:title (title "")
|
||||
#:module-mappings (module-mappings (make-hash)))
|
||||
(format #<<EOF
|
||||
<!DOCTYPE html>
|
||||
<html ~a>
|
||||
|
@ -610,6 +612,9 @@ EOF
|
|||
<title>~a</title>
|
||||
~a
|
||||
~a
|
||||
<script>
|
||||
plt.runtime.currentModuleLoader = plt.runtime.makeLocalFileModuleLoader(~a);
|
||||
</script>
|
||||
<script>
|
||||
~a
|
||||
</script>
|
||||
|
@ -628,6 +633,7 @@ EOF
|
|||
(format " <script src='~a'></script>\n" js))
|
||||
js-files)
|
||||
"")
|
||||
(jsexpr->string module-mappings)
|
||||
invoke-main-module-code))
|
||||
|
||||
|
||||
|
|
|
@ -1127,7 +1127,6 @@
|
|||
// Other module loader implementations may do more interesting
|
||||
// things here, such as loading off the disk, or from the network.
|
||||
var defaultModuleLoader = function(M, moduleName, success, fail) {
|
||||
console.log("request to load", moduleName);
|
||||
if (M.modules[moduleName] instanceof ModuleRecord) {
|
||||
return success();
|
||||
} else {
|
||||
|
@ -1136,31 +1135,25 @@
|
|||
};
|
||||
|
||||
|
||||
var makeLocalFileModuleLoader = function(basepath) {
|
||||
// makeLocalFileModuleLoader: (hashof string string) -> moduleLoader
|
||||
// Given the manifest mapping module names to the files that implement them,
|
||||
// produces a module loader that uses loadscript to get these modules
|
||||
// into memory.
|
||||
var makeLocalFileModuleLoader = function(moduleManifest) {
|
||||
var loadScript = baselib.loadscript.loadScript;
|
||||
return function(M, moduleName, success, fail) {
|
||||
console.log("request to load", moduleName);
|
||||
|
||||
if (M.modules[moduleName] instanceof ModuleRecord) {
|
||||
return success();
|
||||
} else {
|
||||
var onManifestLoaded = function() {
|
||||
// The manifest should map module names to
|
||||
// their files.
|
||||
if (runtime.currentModuleManifest[moduleName]) {
|
||||
var modulePath =
|
||||
(basepath + "/" +
|
||||
runtime.currentModuleManifest[moduleName]);
|
||||
return loadScript(modulePath, success, fail);
|
||||
}
|
||||
// FILL ME IN:
|
||||
// 1. Look up the path in the manifest.
|
||||
// 2. Dynamically load the module in using loadScript
|
||||
// 3. If that succeeds, continue, otherwise, fail.
|
||||
return fail();
|
||||
|
||||
};
|
||||
return loadScript(basepath + "/manifest.js",
|
||||
onManifestLoaded,
|
||||
fail);
|
||||
// The manifest should map module names to
|
||||
// their files.
|
||||
if (moduleManifest[moduleName]) {
|
||||
var modulePath = moduleManifest[moduleName];
|
||||
return loadScript(modulePath, success, fail);
|
||||
}
|
||||
return fail();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -1177,8 +1170,10 @@
|
|||
// Exports
|
||||
var exports = runtime;
|
||||
exports['currentMachine'] = new Machine();
|
||||
|
||||
exports['currentModuleLoader'] = defaultModuleLoader;
|
||||
exports['currentModuleManifest'] = {};
|
||||
exports['makeLocalFileModuleLoader'] = makeLocalFileModuleLoader;
|
||||
|
||||
exports['invokeMains'] = invokeMains;
|
||||
exports['lookupInMains'] = lookupInMains;
|
||||
|
||||
|
@ -1194,6 +1189,9 @@
|
|||
exports['setReadyTrue'] = setReadyTrue;
|
||||
exports['setReadyFalse'] = setReadyFalse;
|
||||
|
||||
|
||||
|
||||
|
||||
exports['Machine'] = Machine;
|
||||
exports['Frame'] = Frame;
|
||||
exports['CallFrame'] = CallFrame;
|
||||
|
|
|
@ -220,11 +220,16 @@
|
|||
(fprintf (current-report-port) "Creating destination directory ~s\n" (current-output-dir))
|
||||
(make-directory* (current-output-dir)))
|
||||
|
||||
|
||||
(define main-module-path (make-output-js-filename #f))
|
||||
;; Write out the main module and its other module dependencies.
|
||||
(parameterize ([current-on-resource on-resource])
|
||||
(call-with-output-file* (make-output-js-filename #f)
|
||||
(lambda (op)
|
||||
(display (get-runtime) op)
|
||||
(display (get-runtime) op))
|
||||
#:exists 'replace)
|
||||
(call-with-output-file* main-module-path
|
||||
(lambda (op)
|
||||
(display (get-inert-code (make-MainModuleSource
|
||||
(normalize-path (build-path f)))
|
||||
make-output-js-filename)
|
||||
|
@ -236,12 +241,22 @@
|
|||
|
||||
(fprintf (current-report-port)
|
||||
(format "Writing html ~s\n" (build-path (current-output-dir) output-html-filename)))
|
||||
(define dynamically-loaded-modules
|
||||
(remove (file-name-from-path main-module-path)
|
||||
(for/list ([(key path) module-mappings])
|
||||
(file-name-from-path path))))
|
||||
(displayln dynamically-loaded-modules)
|
||||
(call-with-output-file* (build-path (current-output-dir) output-html-filename)
|
||||
(lambda (op)
|
||||
(display (get-html-template
|
||||
(map file-name-from-path (reverse written-js-paths))
|
||||
(for*/list ([p (reverse written-js-paths)]
|
||||
[name (in-value (file-name-from-path p))]
|
||||
#:unless (member name dynamically-loaded-modules))
|
||||
name)
|
||||
#:title title
|
||||
#:manifest output-manifest-filename)
|
||||
#:manifest output-manifest-filename
|
||||
#:module-mappings (for/hash ([(key path) module-mappings])
|
||||
(values key (path->string (file-name-from-path path)))))
|
||||
op))
|
||||
#:exists 'replace)
|
||||
|
||||
|
@ -256,6 +271,7 @@
|
|||
(fprintf op "~a\n" js-name))
|
||||
(for [(resource-name written-resources)]
|
||||
(fprintf op "~a\n" resource-name))
|
||||
(fprintf op "~a\n" output-js-module-manifest-filename)
|
||||
(fprintf op "\n# All other resources (e.g. sites) require the user to be online.\nNETWORK:\n*\n"))
|
||||
|
||||
#:exists 'replace)
|
||||
|
@ -268,7 +284,8 @@
|
|||
(fprintf op "plt.runtime.currentModuleManifest=")
|
||||
(write-json (for/hash ([(key path) module-mappings])
|
||||
(values key (path->string (file-name-from-path path))))
|
||||
op))
|
||||
op)
|
||||
(fprintf op ";\n"))
|
||||
#:exists 'replace)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user