aboutsummaryrefslogtreecommitdiff
path: root/static/js/services.js
diff options
context:
space:
mode:
authorDmitri Shuralyov <dmitshur@golang.org>2021-02-13 17:41:38 -0500
committerDmitri Shuralyov <dmitshur@golang.org>2021-03-04 02:13:20 +0000
commitb72029adf3393d3635828fedcddd5ae7053d3250 (patch)
treec3d5051608c9fd17cc97ca4d3a0dd51403440d2f /static/js/services.js
parent004403599411fcd726b1e58cd0199083507d2047 (diff)
downloadgolang-id-tour-b72029adf3393d3635828fedcddd5ae7053d3250.tar.xz
tour: build snippets in module mode
We want to start building snippets in module mode rather than legacy legacy GOPATH mode, to make tour work well when there's no tour code in GOPATH/src and to be more future-proof. Building in module mode means we need to specify a go.mod file to use for each snippet. The tour web UI design predates the module mode and its go.mod files. Txtar-based multi-file support was added to the playground (that the tour uses for executing snippets) in golang.org/issue/32040, but the web UI hasn't been updated to have first-class separate <textarea> elements or tabs for editing multiple files. For now, we can get by with providing a default go.mod file for all tour snippets, since they only need some packages in the tour module. Update to a newer version of the golang.org/x/tools/playground/socket package which includes multi-file snippet support added in CL 204237. For golang/go#44243. Change-Id: Ib05725c52fbe43658b2f22ac728b1e901e635824 Reviewed-on: https://go-review.googlesource.com/c/tour/+/291889 Trust: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'static/js/services.js')
-rwxr-xr-xstatic/js/services.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/static/js/services.js b/static/js/services.js
index dd4563f..da5f79c 100755
--- a/static/js/services.js
+++ b/static/js/services.js
@@ -49,6 +49,29 @@ factory('run', ['$window', 'editor',
};
};
return function(code, output, options, done) {
+ // We want to build tour snippets in module mode, so append
+ // a default go.mod file when it is not already included in
+ // the txtar archive.
+ //
+ // The exercises use golang.org/x/tour/{pic,reader,tree,wc}
+ // packages, so include the golang.org/x/tour module in the
+ // build list.
+ const hasGoMod = code.indexOf('\n-- go.mod --\n') !== -1 || code.startsWith('-- go.mod --\n');
+ if (!hasGoMod) {
+ code += '\n' +
+ '-- go.mod --\n' +
+ 'module example\n' +
+ 'require golang.org/x/tour v0.0.0-20201207214521-004403599411\n' +
+ '-- go.sum --\n' +
+ 'golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=\n' +
+ 'golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=\n' +
+ 'golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\n' +
+ 'golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=\n' +
+ 'golang.org/x/tools v0.0.0-20190312164927-7b79afddac43/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=\n' +
+ 'golang.org/x/tour v0.0.0-20201207214521-004403599411 h1:dJ4kVwSGlrLZXW6eo2IOer4Pm3wl2GIG4fytRziMgL8=\n' +
+ 'golang.org/x/tour v0.0.0-20201207214521-004403599411/go.mod h1:qMugOFWX59KzC8Nx7f2uvXxKxAqJfi1J6ZUHAWKnrRA=\n';
+ }
+
// PlaygroundOutput is defined in playground.js which is prepended
// to the generated script.js in gotour/tour.go.
// The next line removes the jshint warning.