Re-implement working dev-sandbox/watch-dev-sandbox gulp-tasks
				
					
				
			Compared to the, previously removed, `sandbox`/`watch-sandbox` gulp-tasks, these ones should work even when run against an non-existent/empty `build`-folder. Also, to ensure that the development viewer actually works out-of-the-box, `gulp server` will now also include `gulp watch-dev-sandbox` to remove the need to *manually* invoke the build-tasks. Finally, this patch also removes the `web/devcom.js` file since it shouldn't actually be needed, assuming that the "sandbox"-loading code in the `web/genericcom.js` file is actually *correctly* implemented.
This commit is contained in:
		
							parent
							
								
									13d7244529
								
							
						
					
					
						commit
						c39f1aedb2
					
				
							
								
								
									
										68
									
								
								gulpfile.js
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								gulpfile.js
									
									
									
									
									
								
							| @ -173,9 +173,15 @@ function createStringSource(filename, content) { | |||||||
| function createWebpackConfig( | function createWebpackConfig( | ||||||
|   defines, |   defines, | ||||||
|   output, |   output, | ||||||
|   { disableSourceMaps = false, disableLicenseHeader = false } = {} |   { | ||||||
|  |     disableVersionInfo = false, | ||||||
|  |     disableSourceMaps = false, | ||||||
|  |     disableLicenseHeader = false, | ||||||
|  |   } = {} | ||||||
| ) { | ) { | ||||||
|   var versionInfo = getVersionJSON(); |   const versionInfo = !disableVersionInfo | ||||||
|  |     ? getVersionJSON() | ||||||
|  |     : { version: 0, commit: 0 }; | ||||||
|   var bundleDefines = builder.merge(defines, { |   var bundleDefines = builder.merge(defines, { | ||||||
|     BUNDLE_VERSION: versionInfo.version, |     BUNDLE_VERSION: versionInfo.version, | ||||||
|     BUNDLE_BUILD: versionInfo.commit, |     BUNDLE_BUILD: versionInfo.commit, | ||||||
| @ -359,8 +365,9 @@ function createScriptingBundle(defines, extraOptions = undefined) { | |||||||
|     .pipe(replaceJSRootName(scriptingAMDName, "pdfjsScripting")); |     .pipe(replaceJSRootName(scriptingAMDName, "pdfjsScripting")); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function createTemporaryScriptingBundle(defines) { | function createTemporaryScriptingBundle(defines, extraOptions = undefined) { | ||||||
|   return createScriptingBundle(defines, { |   return createScriptingBundle(defines, { | ||||||
|  |     disableVersionInfo: !!(extraOptions && extraOptions.disableVersionInfo), | ||||||
|     disableSourceMaps: true, |     disableSourceMaps: true, | ||||||
|     disableLicenseHeader: true, |     disableLicenseHeader: true, | ||||||
|   }).pipe(gulp.dest(TMP_DIR)); |   }).pipe(gulp.dest(TMP_DIR)); | ||||||
| @ -1711,16 +1718,57 @@ gulp.task( | |||||||
|   }) |   }) | ||||||
| ); | ); | ||||||
| 
 | 
 | ||||||
| gulp.task("server", function () { | gulp.task( | ||||||
|   console.log(); |   "dev-sandbox", | ||||||
|   console.log("### Starting local server"); |   gulp.series( | ||||||
|  |     function scripting() { | ||||||
|  |       const defines = builder.merge(DEFINES, { GENERIC: true, TESTING: true }); | ||||||
|  |       return createTemporaryScriptingBundle(defines, { | ||||||
|  |         disableVersionInfo: true, | ||||||
|  |       }); | ||||||
|  |     }, | ||||||
|  |     function () { | ||||||
|  |       console.log(); | ||||||
|  |       console.log("### Building development sandbox"); | ||||||
| 
 | 
 | ||||||
|   var WebServer = require("./test/webserver.js").WebServer; |       const defines = builder.merge(DEFINES, { GENERIC: true, TESTING: true }); | ||||||
|   var server = new WebServer(); |       const sandboxDir = BUILD_DIR + "dev-sandbox/"; | ||||||
|   server.port = 8888; | 
 | ||||||
|   server.start(); |       rimraf.sync(sandboxDir); | ||||||
|  | 
 | ||||||
|  |       return createSandboxBundle(defines, { | ||||||
|  |         disableVersionInfo: true, | ||||||
|  |       }).pipe(gulp.dest(sandboxDir)); | ||||||
|  |     } | ||||||
|  |   ) | ||||||
|  | ); | ||||||
|  | 
 | ||||||
|  | gulp.task("watch-dev-sandbox", function () { | ||||||
|  |   gulp.watch( | ||||||
|  |     [ | ||||||
|  |       "src/pdf.{sandbox,scripting}.js", | ||||||
|  |       "src/scripting_api/*.js", | ||||||
|  |       "src/shared/scripting_utils.js", | ||||||
|  |       "external/quickjs/*.js", | ||||||
|  |     ], | ||||||
|  |     { ignoreInitial: false }, | ||||||
|  |     gulp.series("dev-sandbox") | ||||||
|  |   ); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | gulp.task( | ||||||
|  |   "server", | ||||||
|  |   gulp.parallel("watch-dev-sandbox", function () { | ||||||
|  |     console.log(); | ||||||
|  |     console.log("### Starting local server"); | ||||||
|  | 
 | ||||||
|  |     var WebServer = require("./test/webserver.js").WebServer; | ||||||
|  |     var server = new WebServer(); | ||||||
|  |     server.port = 8888; | ||||||
|  |     server.start(); | ||||||
|  |   }) | ||||||
|  | ); | ||||||
|  | 
 | ||||||
| gulp.task("clean", function (done) { | gulp.task("clean", function (done) { | ||||||
|   console.log(); |   console.log(); | ||||||
|   console.log("### Cleaning up project builds"); |   console.log("### Cleaning up project builds"); | ||||||
|  | |||||||
| @ -223,14 +223,6 @@ const defaultOptions = { | |||||||
|     value: false, |     value: false, | ||||||
|     kind: OptionKind.API, |     kind: OptionKind.API, | ||||||
|   }, |   }, | ||||||
|   scriptingSrc: { |  | ||||||
|     /** @type {string} */ |  | ||||||
|     value: |  | ||||||
|       typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION") |  | ||||||
|         ? "../build/generic/build/pdf.sandbox.js" |  | ||||||
|         : "../build/pdf.sandbox.js", |  | ||||||
|     kind: OptionKind.VIEWER, |  | ||||||
|   }, |  | ||||||
|   verbosity: { |   verbosity: { | ||||||
|     /** @type {number} */ |     /** @type {number} */ | ||||||
|     value: 1, |     value: 1, | ||||||
| @ -265,6 +257,14 @@ if ( | |||||||
|     value: typeof navigator !== "undefined" ? navigator.language : "en-US", |     value: typeof navigator !== "undefined" ? navigator.language : "en-US", | ||||||
|     kind: OptionKind.VIEWER, |     kind: OptionKind.VIEWER, | ||||||
|   }; |   }; | ||||||
|  |   defaultOptions.sandboxBundleSrc = { | ||||||
|  |     /** @type {string} */ | ||||||
|  |     value: | ||||||
|  |       typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION") | ||||||
|  |         ? "../build/dev-sandbox/pdf.sandbox.js" | ||||||
|  |         : "../build/pdf.sandbox.js", | ||||||
|  |     kind: OptionKind.VIEWER, | ||||||
|  |   }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const userOptions = Object.create(null); | const userOptions = Object.create(null); | ||||||
|  | |||||||
| @ -1,43 +0,0 @@ | |||||||
| /* Copyright 2017 Mozilla Foundation |  | ||||||
|  * |  | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  | ||||||
|  * you may not use this file except in compliance with the License. |  | ||||||
|  * You may obtain a copy of the License at |  | ||||||
|  * |  | ||||||
|  *     http://www.apache.org/licenses/LICENSE-2.0
 |  | ||||||
|  * |  | ||||||
|  * Unless required by applicable law or agreed to in writing, software |  | ||||||
|  * distributed under the License is distributed on an "AS IS" BASIS, |  | ||||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |  | ||||||
|  * See the License for the specific language governing permissions and |  | ||||||
|  * limitations under the License. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| import { DefaultExternalServices, PDFViewerApplication } from "./app.js"; |  | ||||||
| import { loadScript, shadow } from "pdfjs-lib"; |  | ||||||
| 
 |  | ||||||
| const DevCom = {}; |  | ||||||
| 
 |  | ||||||
| class DevExternalServices extends DefaultExternalServices { |  | ||||||
|   static get scripting() { |  | ||||||
|     const promise = loadScript("../build/pdf.sandbox.js").then(() => { |  | ||||||
|       return window.pdfjsSandbox.QuickJSSandbox(); |  | ||||||
|     }); |  | ||||||
|     const sandbox = { |  | ||||||
|       createSandbox(data) { |  | ||||||
|         promise.then(sbx => sbx.create(data)); |  | ||||||
|       }, |  | ||||||
|       dispatchEventInSandbox(event) { |  | ||||||
|         promise.then(sbx => sbx.dispatchEvent(event)); |  | ||||||
|       }, |  | ||||||
|       destroySandbox() { |  | ||||||
|         promise.then(sbx => sbx.nukeSandbox()); |  | ||||||
|       }, |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     return shadow(this, "scripting", sandbox); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| PDFViewerApplication.externalServices = DevExternalServices; |  | ||||||
| 
 |  | ||||||
| export { DevCom }; |  | ||||||
| @ -53,7 +53,7 @@ class GenericExternalServices extends DefaultExternalServices { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   static get scripting() { |   static get scripting() { | ||||||
|     const promise = loadScript(AppOptions.get("scriptingSrc")).then(() => { |     const promise = loadScript(AppOptions.get("sandboxBundleSrc")).then(() => { | ||||||
|       return window.pdfjsSandbox.QuickJSSandbox(); |       return window.pdfjsSandbox.QuickJSSandbox(); | ||||||
|     }); |     }); | ||||||
|     const sandbox = { |     const sandbox = { | ||||||
|  | |||||||
| @ -56,9 +56,6 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC")) { | |||||||
| if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { | if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { | ||||||
|   require("./chromecom.js"); |   require("./chromecom.js"); | ||||||
| } | } | ||||||
| if (typeof PDFJSDev === "undefined") { |  | ||||||
|   import("./devcom.js"); |  | ||||||
| } |  | ||||||
| if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME || GENERIC")) { | if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME || GENERIC")) { | ||||||
|   require("./pdf_print_service.js"); |   require("./pdf_print_service.js"); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user