@rindo/core 1.8.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +27 -0
- package/bin/rindo +22 -0
- package/build-conditionals/index.d.ts +2 -0
- package/build-conditionals/index.mjs +66 -0
- package/build-conditionals/package.json +6 -0
- package/compiler/index.js +2 -0
- package/compiler/package.json +6 -0
- package/compiler/rindo.js +6765 -0
- package/dist/cli/index.js +6068 -0
- package/dist/client/css-shim-14a9812e.js +656 -0
- package/dist/client/css-shim-69821662.js +658 -0
- package/dist/client/declarations/rindo.core.d.ts +1347 -0
- package/dist/client/dom-68c8fe31.js +139 -0
- package/dist/client/dom-af01458a.js +137 -0
- package/dist/client/index.js +2937 -0
- package/dist/client/index.mjs +2820 -0
- package/dist/client/polyfills/core-js.js +10 -0
- package/dist/client/polyfills/css-shim.js +656 -0
- package/dist/client/polyfills/dom.js +146 -0
- package/dist/client/polyfills/es5-html-element.js +18 -0
- package/dist/client/polyfills/index.js +35 -0
- package/dist/client/polyfills/promise.js +9 -0
- package/dist/client/polyfills/system.js +6 -0
- package/dist/client/shadow-css-6ef31c68.js +386 -0
- package/dist/client/shadow-css-8fd1a9e4.js +388 -0
- package/dist/compiler/app-core/app-es5-disabled.d.ts +2 -0
- package/dist/compiler/app-core/app-polyfills.d.ts +3 -0
- package/dist/compiler/app-core/build-conditionals.d.ts +6 -0
- package/dist/compiler/app-core/bundle-app-core.d.ts +6 -0
- package/dist/compiler/app-core/component-styles.d.ts +4 -0
- package/dist/compiler/app-core/format-component-runtime-meta.d.ts +4 -0
- package/dist/compiler/app-core/optimize-module.d.ts +7 -0
- package/dist/compiler/browser/build-conditionals-client.d.ts +3 -0
- package/dist/compiler/browser/compile-options.d.ts +12 -0
- package/dist/compiler/browser/compile.d.ts +2 -0
- package/dist/compiler/browser/create-compiler.d.ts +14 -0
- package/dist/compiler/browser/index.d.ts +11 -0
- package/dist/compiler/build/build-ctx.d.ts +74 -0
- package/dist/compiler/build/build-finish.d.ts +3 -0
- package/dist/compiler/build/build-hmr.d.ts +2 -0
- package/dist/compiler/build/build-results.d.ts +2 -0
- package/dist/compiler/build/build-stats.d.ts +3 -0
- package/dist/compiler/build/build.d.ts +2 -0
- package/dist/compiler/build/cache-stats.d.ts +4 -0
- package/dist/compiler/build/compiler-build-id.d.ts +6 -0
- package/dist/compiler/build/compiler-ctx.d.ts +44 -0
- package/dist/compiler/build/init-index-html.d.ts +2 -0
- package/dist/compiler/build/validate-files.d.ts +2 -0
- package/dist/compiler/build/write-build.d.ts +2 -0
- package/dist/compiler/cache.d.ts +22 -0
- package/dist/compiler/compiler.d.ts +27 -0
- package/dist/compiler/component-hydrate/bundle-hydrate-factory.d.ts +3 -0
- package/dist/compiler/component-hydrate/generate-hydrate-app.d.ts +2 -0
- package/dist/compiler/component-hydrate/hydrate-factory-closure.d.ts +2 -0
- package/dist/compiler/component-hydrate/update-to-hydrate-components.d.ts +2 -0
- package/dist/compiler/component-hydrate/write-hydrate-outputs.d.ts +3 -0
- package/dist/compiler/component-lazy/generate-cjs.d.ts +3 -0
- package/dist/compiler/component-lazy/generate-esm-browser.d.ts +3 -0
- package/dist/compiler/component-lazy/generate-esm.d.ts +3 -0
- package/dist/compiler/component-lazy/generate-lazy-app.d.ts +3 -0
- package/dist/compiler/component-lazy/generate-lazy-module.d.ts +4 -0
- package/dist/compiler/component-lazy/generate-system.d.ts +3 -0
- package/dist/compiler/component-lazy/update-to-lazy-component.d.ts +2 -0
- package/dist/compiler/component-lazy/write-lazy-entry-module.d.ts +2 -0
- package/dist/compiler/component-native/update-to-native-component.d.ts +2 -0
- package/dist/compiler/config/config-reload.d.ts +3 -0
- package/dist/compiler/config/config-utils.d.ts +4 -0
- package/dist/compiler/config/validate-config.d.ts +4 -0
- package/dist/compiler/config/validate-copy.d.ts +2 -0
- package/dist/compiler/config/validate-dev-server.d.ts +2 -0
- package/dist/compiler/config/validate-docs.d.ts +2 -0
- package/dist/compiler/config/validate-namespace.d.ts +3 -0
- package/dist/compiler/config/validate-output-stats.d.ts +2 -0
- package/dist/compiler/config/validate-outputs-angular.d.ts +2 -0
- package/dist/compiler/config/validate-outputs-custom.d.ts +2 -0
- package/dist/compiler/config/validate-outputs-dist-module.d.ts +2 -0
- package/dist/compiler/config/validate-outputs-dist.d.ts +2 -0
- package/dist/compiler/config/validate-outputs-hydrate-script.d.ts +2 -0
- package/dist/compiler/config/validate-outputs-www.d.ts +2 -0
- package/dist/compiler/config/validate-outputs.d.ts +2 -0
- package/dist/compiler/config/validate-paths.d.ts +2 -0
- package/dist/compiler/config/validate-plugins.d.ts +2 -0
- package/dist/compiler/config/validate-prerender.d.ts +2 -0
- package/dist/compiler/config/validate-rollup-config.d.ts +2 -0
- package/dist/compiler/config/validate-service-worker.d.ts +2 -0
- package/dist/compiler/config/validate-testing.d.ts +2 -0
- package/dist/compiler/config/validate-workers.d.ts +2 -0
- package/dist/compiler/copy/assets-copy-tasks.d.ts +3 -0
- package/dist/compiler/copy/hashed-copy.d.ts +2 -0
- package/dist/compiler/copy/local-copy-tasks.d.ts +3 -0
- package/dist/compiler/docs/constants.d.ts +2 -0
- package/dist/compiler/docs/custom/index.d.ts +2 -0
- package/dist/compiler/docs/docs.d.ts +2 -0
- package/dist/compiler/docs/generate-doc-data.d.ts +3 -0
- package/dist/compiler/docs/json/index.d.ts +3 -0
- package/dist/compiler/docs/readme/docs-util.d.ts +13 -0
- package/dist/compiler/docs/readme/index.d.ts +3 -0
- package/dist/compiler/docs/readme/markdown-css-props.d.ts +2 -0
- package/dist/compiler/docs/readme/markdown-dependencies.d.ts +2 -0
- package/dist/compiler/docs/readme/markdown-events.d.ts +2 -0
- package/dist/compiler/docs/readme/markdown-methods.d.ts +2 -0
- package/dist/compiler/docs/readme/markdown-props.d.ts +2 -0
- package/dist/compiler/docs/readme/markdown-slots.d.ts +2 -0
- package/dist/compiler/docs/readme/markdown-usage.d.ts +6 -0
- package/dist/compiler/docs/readme/output-docs.d.ts +3 -0
- package/dist/compiler/docs/style-docs.d.ts +2 -0
- package/dist/compiler/docs/vscode/index.d.ts +2 -0
- package/dist/compiler/entries/component-bundles.d.ts +3 -0
- package/dist/compiler/entries/component-graph.d.ts +2 -0
- package/dist/compiler/entries/default-bundles.d.ts +3 -0
- package/dist/compiler/entries/entry-modules.d.ts +6 -0
- package/dist/compiler/entries/resolve-component-dependencies.d.ts +2 -0
- package/dist/compiler/events.d.ts +15 -0
- package/dist/compiler/fs-watch/fs-watch-init.d.ts +2 -0
- package/dist/compiler/fs-watch/fs-watch-log.d.ts +2 -0
- package/dist/compiler/fs-watch/fs-watch-rebuild.d.ts +7 -0
- package/dist/compiler/html/inject-module-preloads.d.ts +3 -0
- package/dist/compiler/html/inject-sw-script.d.ts +4 -0
- package/dist/compiler/html/inline-esm-import.d.ts +2 -0
- package/dist/compiler/html/inline-style-sheets.d.ts +2 -0
- package/dist/compiler/html/update-global-styles-link.d.ts +2 -0
- package/dist/compiler/html/used-components.d.ts +2 -0
- package/dist/compiler/html/utils.d.ts +2 -0
- package/dist/compiler/html/validate-manifest-json.d.ts +2 -0
- package/dist/compiler/index.d.ts +10 -0
- package/dist/compiler/index.js +18008 -0
- package/dist/compiler/output-targets/empty-dir.d.ts +6 -0
- package/dist/compiler/output-targets/index.d.ts +2 -0
- package/dist/compiler/output-targets/output-angular.d.ts +4 -0
- package/dist/compiler/output-targets/output-app.d.ts +4 -0
- package/dist/compiler/output-targets/output-collection.d.ts +3 -0
- package/dist/compiler/output-targets/output-copy.d.ts +2 -0
- package/dist/compiler/output-targets/output-custom.d.ts +2 -0
- package/dist/compiler/output-targets/output-docs.d.ts +2 -0
- package/dist/compiler/output-targets/output-hydrate.d.ts +2 -0
- package/dist/compiler/output-targets/output-lazy-loader.d.ts +2 -0
- package/dist/compiler/output-targets/output-module.d.ts +4 -0
- package/dist/compiler/output-targets/output-prerender.d.ts +2 -0
- package/dist/compiler/output-targets/output-service-workers.d.ts +2 -0
- package/dist/compiler/output-targets/output-types.d.ts +2 -0
- package/dist/compiler/output-targets/output-utils.d.ts +54 -0
- package/dist/compiler/output-targets/output-www.d.ts +2 -0
- package/dist/compiler/plugin/plugin.d.ts +6 -0
- package/dist/compiler/polyfills.d.ts +0 -0
- package/dist/compiler/prerender/crawl-urls.d.ts +3 -0
- package/dist/compiler/prerender/host-config.d.ts +12 -0
- package/dist/compiler/prerender/prerender-config.d.ts +2 -0
- package/dist/compiler/prerender/prerender-main.d.ts +2 -0
- package/dist/compiler/prerender/prerender-queue.d.ts +3 -0
- package/dist/compiler/prerender/prerender-template-html.d.ts +2 -0
- package/dist/compiler/prerender/prerendered-write-path.d.ts +2 -0
- package/dist/compiler/prerender/robots-txt.d.ts +2 -0
- package/dist/compiler/prerender/sitemap-xml.d.ts +3 -0
- package/dist/compiler/rollup-plugins/component-entry.d.ts +3 -0
- package/dist/compiler/rollup-plugins/css-transformer.d.ts +3 -0
- package/dist/compiler/rollup-plugins/global-scripts.d.ts +4 -0
- package/dist/compiler/rollup-plugins/image-plugin.d.ts +3 -0
- package/dist/compiler/rollup-plugins/in-memory-fs-read.d.ts +3 -0
- package/dist/compiler/rollup-plugins/loader.d.ts +4 -0
- package/dist/compiler/rollup-plugins/plugin-helper.d.ts +5 -0
- package/dist/compiler/rollup-plugins/rindo-build-conditionals.d.ts +7 -0
- package/dist/compiler/rollup-plugins/rindo-client.d.ts +3 -0
- package/dist/compiler/rollup-plugins/rindo-external-runtime.d.ts +2 -0
- package/dist/compiler/rollup-plugins/rindo-hydrate.d.ts +3 -0
- package/dist/compiler/rollup-plugins/rindo-public-plugin.d.ts +2 -0
- package/dist/compiler/service-worker/generate-sw.d.ts +7 -0
- package/dist/compiler/service-worker/service-worker-util.d.ts +2 -0
- package/dist/compiler/style/cached-styles.d.ts +5 -0
- package/dist/compiler/style/component-styles.d.ts +2 -0
- package/dist/compiler/style/css-imports.d.ts +9 -0
- package/dist/compiler/style/css-to-esm.d.ts +5 -0
- package/dist/compiler/style/generate-styles.d.ts +2 -0
- package/dist/compiler/style/global-styles.d.ts +3 -0
- package/dist/compiler/style/normalize-styles.d.ts +2 -0
- package/dist/compiler/style/optimize-css.d.ts +2 -0
- package/dist/compiler/style/scope-css.d.ts +3 -0
- package/dist/compiler/style/style-utils.d.ts +10 -0
- package/dist/compiler/transformers/add-component-meta-proxy.d.ts +3 -0
- package/dist/compiler/transformers/add-component-meta-static.d.ts +4 -0
- package/dist/compiler/transformers/add-imports.d.ts +3 -0
- package/dist/compiler/transformers/collections/add-external-import.d.ts +2 -0
- package/dist/compiler/transformers/collections/parse-collection-components.d.ts +2 -0
- package/dist/compiler/transformers/collections/parse-collection-deprecated.d.ts +2 -0
- package/dist/compiler/transformers/collections/parse-collection-manifest.d.ts +7 -0
- package/dist/compiler/transformers/collections/parse-collection-module.d.ts +2 -0
- package/dist/compiler/transformers/component-build-conditionals.d.ts +2 -0
- package/dist/compiler/transformers/component-hydrate/hydrate-component.d.ts +3 -0
- package/dist/compiler/transformers/component-hydrate/hydrate-runtime-cmp-meta.d.ts +3 -0
- package/dist/compiler/transformers/component-hydrate/tranform-to-hydrate-component.d.ts +2 -0
- package/dist/compiler/transformers/component-lazy/lazy-component.d.ts +3 -0
- package/dist/compiler/transformers/component-lazy/lazy-constructor.d.ts +3 -0
- package/dist/compiler/transformers/component-lazy/lazy-element-getter.d.ts +3 -0
- package/dist/compiler/transformers/component-lazy/transform-lazy-component.d.ts +4 -0
- package/dist/compiler/transformers/component-native/native-component.d.ts +3 -0
- package/dist/compiler/transformers/component-native/native-connected-callback.d.ts +3 -0
- package/dist/compiler/transformers/component-native/native-constructor.d.ts +3 -0
- package/dist/compiler/transformers/component-native/native-element-getter.d.ts +3 -0
- package/dist/compiler/transformers/component-native/native-static-style.d.ts +3 -0
- package/dist/compiler/transformers/component-native/tranform-to-native-component.d.ts +4 -0
- package/dist/compiler/transformers/core-runtime-apis.d.ts +30 -0
- package/dist/compiler/transformers/create-event.d.ts +3 -0
- package/dist/compiler/transformers/decorators-to-static/component-decorator.d.ts +3 -0
- package/dist/compiler/transformers/decorators-to-static/convert-decorators.d.ts +3 -0
- package/dist/compiler/transformers/decorators-to-static/decorator-utils.d.ts +10 -0
- package/dist/compiler/transformers/decorators-to-static/element-decorator.d.ts +3 -0
- package/dist/compiler/transformers/decorators-to-static/event-decorator.d.ts +4 -0
- package/dist/compiler/transformers/decorators-to-static/listen-decorator.d.ts +6 -0
- package/dist/compiler/transformers/decorators-to-static/method-decorator.d.ts +3 -0
- package/dist/compiler/transformers/decorators-to-static/prop-decorator.d.ts +4 -0
- package/dist/compiler/transformers/decorators-to-static/state-decorator.d.ts +3 -0
- package/dist/compiler/transformers/decorators-to-static/style-to-static.d.ts +3 -0
- package/dist/compiler/transformers/decorators-to-static/watch-decorator.d.ts +3 -0
- package/dist/compiler/transformers/define-custom-element.d.ts +3 -0
- package/dist/compiler/transformers/host-data-transform.d.ts +3 -0
- package/dist/compiler/transformers/legacy-props.d.ts +3 -0
- package/dist/compiler/transformers/remove-static-meta-properties.d.ts +2 -0
- package/dist/compiler/transformers/reserved-public-members.d.ts +3 -0
- package/dist/compiler/transformers/rindo-import-path.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/call-expression.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/class-methods.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/component.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/element-ref.d.ts +2 -0
- package/dist/compiler/transformers/static-to-meta/encapsulation.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/events.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/import.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/listeners.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/methods.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/props.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/states.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/string-literal.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/styles.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/vdom.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/visitor.d.ts +3 -0
- package/dist/compiler/transformers/static-to-meta/watchers.d.ts +3 -0
- package/dist/compiler/transformers/style-imports.d.ts +3 -0
- package/dist/compiler/transformers/transform-utils.d.ts +31 -0
- package/dist/compiler/transformers/update-component-class.d.ts +3 -0
- package/dist/compiler/transformers/update-rindo-core-import.d.ts +3 -0
- package/dist/compiler/transformers/watcher-meta-transform.d.ts +3 -0
- package/dist/compiler/transpile/compiler-options.d.ts +4 -0
- package/dist/compiler/transpile/transpile-app.d.ts +2 -0
- package/dist/compiler/transpile/transpile-module.d.ts +5 -0
- package/dist/compiler/transpile/transpile-service.d.ts +3 -0
- package/dist/compiler/transpile/transpile-to-es5-main.d.ts +2 -0
- package/dist/compiler/transpile/validate-types-main.d.ts +2 -0
- package/dist/compiler/types/generate-app-types.d.ts +2 -0
- package/dist/compiler/types/generate-component-types.d.ts +8 -0
- package/dist/compiler/types/generate-event-types.d.ts +2 -0
- package/dist/compiler/types/generate-method-types.d.ts +2 -0
- package/dist/compiler/types/generate-prop-types.d.ts +2 -0
- package/dist/compiler/types/generate-types.d.ts +2 -0
- package/dist/compiler/types/rindo-types.d.ts +3 -0
- package/dist/compiler/types/types-utils.d.ts +4 -0
- package/dist/compiler/types/update-import-refs.d.ts +11 -0
- package/dist/compiler/types/validate-package-json.d.ts +9 -0
- package/dist/declarations/assets.d.ts +17 -0
- package/dist/declarations/browser-compile.d.ts +47 -0
- package/dist/declarations/build-conditionals.d.ts +91 -0
- package/dist/declarations/build-events.d.ts +19 -0
- package/dist/declarations/build.d.ts +247 -0
- package/dist/declarations/cache.d.ts +11 -0
- package/dist/declarations/collection-manifest.d.ts +106 -0
- package/dist/declarations/collection.d.ts +139 -0
- package/dist/declarations/compiler.d.ts +53 -0
- package/dist/declarations/component-compiler-meta.d.ts +198 -0
- package/dist/declarations/component-constructor.d.ts +61 -0
- package/dist/declarations/component-interfaces.d.ts +123 -0
- package/dist/declarations/config.d.ts +409 -0
- package/dist/declarations/css-var-shim.d.ts +9 -0
- package/dist/declarations/decorators.d.ts +150 -0
- package/dist/declarations/dev-server.d.ts +135 -0
- package/dist/declarations/diagnostics.d.ts +21 -0
- package/dist/declarations/docs.d.ts +101 -0
- package/dist/declarations/entry.d.ts +28 -0
- package/dist/declarations/events.d.ts +13 -0
- package/dist/declarations/file-system.d.ts +91 -0
- package/dist/declarations/fs-watch.d.ts +15 -0
- package/dist/declarations/host-element.d.ts +53 -0
- package/dist/declarations/hydrate.d.ts +99 -0
- package/dist/declarations/in-memory-fs.d.ts +59 -0
- package/dist/declarations/index.d.ts +45 -0
- package/dist/declarations/jsdoc.d.ts +16 -0
- package/dist/declarations/jsx.d.ts +1050 -0
- package/dist/declarations/logger.d.ts +25 -0
- package/dist/declarations/minify-js.d.ts +11 -0
- package/dist/declarations/module.d.ts +35 -0
- package/dist/declarations/optimize-css.d.ts +12 -0
- package/dist/declarations/output-targets.d.ts +189 -0
- package/dist/declarations/plugin.d.ts +23 -0
- package/dist/declarations/prerender.d.ts +79 -0
- package/dist/declarations/render.d.ts +62 -0
- package/dist/declarations/runtime.d.ts +92 -0
- package/dist/declarations/screenshots.d.ts +192 -0
- package/dist/declarations/server.d.ts +19 -0
- package/dist/declarations/style.d.ts +35 -0
- package/dist/declarations/system.d.ts +174 -0
- package/dist/declarations/testing.d.ts +523 -0
- package/dist/declarations/transpile.d.ts +24 -0
- package/dist/declarations/types.d.ts +24 -0
- package/dist/declarations/vdom.d.ts +55 -0
- package/dist/declarations/worker.d.ts +33 -0
- package/dist/dev-server/content-type-db.json +1 -0
- package/dist/dev-server/index.js +887 -0
- package/dist/dev-server/static/app-error.css +257 -0
- package/dist/dev-server/static/dev-server-client.html +13 -0
- package/dist/dev-server/static/favicon.ico +0 -0
- package/dist/dev-server/templates/directory-index.html +132 -0
- package/dist/dev-server/templates/initial-load.html +160 -0
- package/dist/hydrate/index.d.ts +101 -0
- package/dist/hydrate/index.mjs +1281 -0
- package/dist/hydrate/platform.mjs +347 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.js +1 -0
- package/dist/mock-doc/index.d.ts +851 -0
- package/dist/mock-doc/index.js +3982 -0
- package/dist/mock-doc/index.mjs +3954 -0
- package/dist/runtime/index.js +2576 -0
- package/dist/runtime/index.mjs +2521 -0
- package/dist/runtime/shadow-css-6ef31c68.js +386 -0
- package/dist/runtime/shadow-css-8fd1a9e4.js +388 -0
- package/dist/screenshot/connector-base.d.ts +42 -0
- package/dist/screenshot/connector-local.d.ts +7 -0
- package/dist/screenshot/index.d.ts +3 -0
- package/dist/screenshot/index.js +520 -0
- package/dist/screenshot/pixel-match.d.ts +1 -0
- package/dist/screenshot/screenshot-fs.d.ts +15 -0
- package/dist/sys/node/graceful-fs.js +975 -0
- package/dist/sys/node/index.js +33545 -0
- package/dist/sys/node/node-fetch.js +1779 -0
- package/dist/sys/node/open-in-editor.js +734 -0
- package/dist/sys/node/sys-worker.js +67035 -0
- package/dist/sys/node/visualstudio.vbs +82 -0
- package/dist/sys/node/websocket.js +3728 -0
- package/dist/sys/node/xdg-open +1066 -0
- package/dist/testing/build-conditionals.d.ts +4 -0
- package/dist/testing/build-conditionals.js +43 -0
- package/dist/testing/core.d.ts +35 -0
- package/dist/testing/core.js +52 -0
- package/dist/testing/index.d.ts +13 -0
- package/dist/testing/index.js +40511 -0
- package/dist/testing/jest/jest-config.d.ts +4 -0
- package/dist/testing/jest/jest-environment.d.ts +12 -0
- package/dist/testing/jest/jest-preprocessor.d.ts +10 -0
- package/dist/testing/jest/jest-runner.d.ts +5 -0
- package/dist/testing/jest/jest-screenshot.d.ts +2 -0
- package/dist/testing/jest/jest-serializer.d.ts +5 -0
- package/dist/testing/jest/jest-setup-test-framework.d.ts +1 -0
- package/dist/testing/matchers/attributes.d.ts +14 -0
- package/dist/testing/matchers/class-list.d.ts +12 -0
- package/dist/testing/matchers/events.d.ts +13 -0
- package/dist/testing/matchers/html.d.ts +12 -0
- package/dist/testing/matchers/index.d.ts +21 -0
- package/dist/testing/matchers/screenshot.d.ts +5 -0
- package/dist/testing/matchers/text.d.ts +4 -0
- package/dist/testing/mock-fetch.d.ts +46 -0
- package/dist/testing/mocks.d.ts +12 -0
- package/dist/testing/platform.d.ts +23 -0
- package/dist/testing/platform.js +321 -0
- package/dist/testing/puppeteer/puppeteer-browser.d.ts +6 -0
- package/dist/testing/puppeteer/puppeteer-declarations.d.ts +396 -0
- package/dist/testing/puppeteer/puppeteer-element.d.ts +65 -0
- package/dist/testing/puppeteer/puppeteer-emulate.d.ts +2 -0
- package/dist/testing/puppeteer/puppeteer-events.d.ts +21 -0
- package/dist/testing/puppeteer/puppeteer-find.d.ts +5 -0
- package/dist/testing/puppeteer/puppeteer-page.d.ts +2 -0
- package/dist/testing/puppeteer/puppeteer-screenshot.d.ts +4 -0
- package/dist/testing/spec-page.d.ts +5 -0
- package/dist/testing/task-queue.d.ts +15 -0
- package/dist/testing/test-transpile.d.ts +5 -0
- package/dist/testing/testing-fs.d.ts +31 -0
- package/dist/testing/testing-logger.d.ts +23 -0
- package/dist/testing/testing-sys.d.ts +19 -0
- package/dist/testing/testing-utils.d.ts +5 -0
- package/dist/testing/testing.d.ts +12 -0
- package/dist/utils/index.js +1575 -0
- package/dist/utils/index.mjs +1511 -0
- package/internal/client/build-conditionals.mjs +82 -0
- package/internal/client/css-shim.rindo-client.mjs +656 -0
- package/internal/client/dom.rindo-client.mjs +137 -0
- package/internal/client/index.mjs +2859 -0
- package/internal/client/polyfills/core-js.js +10 -0
- package/internal/client/polyfills/css-shim.js +656 -0
- package/internal/client/polyfills/dom.js +146 -0
- package/internal/client/polyfills/es5-html-element.js +18 -0
- package/internal/client/polyfills/index.js +35 -0
- package/internal/client/polyfills/promise.js +9 -0
- package/internal/client/polyfills/system.js +6 -0
- package/internal/client/shadow-css.rindo-client.mjs +386 -0
- package/internal/images.d.ts +5 -0
- package/internal/index.d.ts +18 -0
- package/internal/index.js +1 -0
- package/internal/package.json +6 -0
- package/mock-doc/index.js +2 -0
- package/mock-doc/package.json +10 -0
- package/package.json +186 -0
- package/readme.md +174 -0
- package/runtime/package.json +5 -0
- package/screenshot/compare/assets/favicon.ico +0 -0
- package/screenshot/compare/assets/logo.png +0 -0
- package/screenshot/compare/build/app.css +1 -0
- package/screenshot/compare/build/app.esm.js +1 -0
- package/screenshot/compare/build/app.js +818 -0
- package/screenshot/compare/build/p-020f8d73.js +1 -0
- package/screenshot/compare/build/p-09qdknbg.system.entry.js +1 -0
- package/screenshot/compare/build/p-0a13mpsc.system.entry.js +1 -0
- package/screenshot/compare/build/p-113f7459.js +1 -0
- package/screenshot/compare/build/p-168ec2c4.system.js +1 -0
- package/screenshot/compare/build/p-2ab1fdf1.system.js +1 -0
- package/screenshot/compare/build/p-2pxcsgrj.entry.js +1 -0
- package/screenshot/compare/build/p-42fb7034.system.js +1 -0
- package/screenshot/compare/build/p-54d9d7c2.system.js +1 -0
- package/screenshot/compare/build/p-67c1f911.js +1 -0
- package/screenshot/compare/build/p-68613371.system.js +1 -0
- package/screenshot/compare/build/p-7dvsjpu0.entry.js +1 -0
- package/screenshot/compare/build/p-aa67fb06.js +1 -0
- package/screenshot/compare/build/p-aeb3cec1.system.js +1 -0
- package/screenshot/compare/build/p-b6e44a24.js +1 -0
- package/screenshot/compare/build/p-c1c25b8a.js +1 -0
- package/screenshot/compare/build/p-c9bopbjy.system.entry.js +1 -0
- package/screenshot/compare/build/p-c9iqz1pp.system.entry.js +1 -0
- package/screenshot/compare/build/p-dizjz8rg.entry.js +1 -0
- package/screenshot/compare/build/p-dnta0rwp.system.entry.js +1 -0
- package/screenshot/compare/build/p-e9670d22.system.js +1 -0
- package/screenshot/compare/build/p-efb0eac6.js +1 -0
- package/screenshot/compare/build/p-ei9jkpd0.system.entry.js +1 -0
- package/screenshot/compare/build/p-ejpsp3kx.js +1 -0
- package/screenshot/compare/build/p-ejwcppol.entry.js +1 -0
- package/screenshot/compare/build/p-f6612d5d.system.js +1 -0
- package/screenshot/compare/build/p-foiivsfc.css +1 -0
- package/screenshot/compare/build/p-gpjjyogx.entry.js +1 -0
- package/screenshot/compare/build/p-howklem2.system.entry.js +1 -0
- package/screenshot/compare/build/p-knv9wvoc.entry.js +1 -0
- package/screenshot/compare/build/p-nsqsfhhy.entry.js +1 -0
- package/screenshot/compare/build/p-ojt278pp.entry.js +1 -0
- package/screenshot/compare/build/p-oywass99.entry.js +1 -0
- package/screenshot/compare/build/p-q3ujhub6.entry.js +1 -0
- package/screenshot/compare/build/p-qw4xnmxv.entry.js +1 -0
- package/screenshot/compare/build/p-t1wvevhc.system.entry.js +1 -0
- package/screenshot/compare/build/p-tnjarrex.system.entry.js +1 -0
- package/screenshot/compare/build/p-vhfpd6kk.system.entry.js +1 -0
- package/screenshot/compare/build/p-vk6rhemd.system.entry.js +1 -0
- package/screenshot/compare/build/p-w6bnm16k.entry.js +1 -0
- package/screenshot/compare/build/p-xje6d7zl.system.entry.js +1 -0
- package/screenshot/compare/build/p-y5jlrcha.system.entry.js +1 -0
- package/screenshot/compare/build/p-yh170wkt.entry.js +1 -0
- package/screenshot/compare/host.config.json +15 -0
- package/screenshot/compare/index.html +1 -0
- package/screenshot/compare/manifest.json +13 -0
- package/screenshot/connector.js +3 -0
- package/screenshot/index.js +2 -0
- package/screenshot/local-connector.js +3 -0
- package/screenshot/package.json +13 -0
- package/screenshot/pixel-match.js +2660 -0
- package/sys/node/index.js +2 -0
- package/sys/node/package.json +5 -0
- package/testing/index.js +2 -0
- package/testing/jest-environment.js +3 -0
- package/testing/jest-preprocessor.js +3 -0
- package/testing/jest-preset.js +40 -0
- package/testing/jest-runner.js +3 -0
- package/testing/jest-setuptestframework.js +3 -0
- package/testing/jest.preprocessor.js +7 -0
- package/testing/package.json +6 -0
|
@@ -0,0 +1,887 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
4
|
+
|
|
5
|
+
var node = require('../sys/node');
|
|
6
|
+
var utils = require('../utils');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
var path__default = _interopDefault(path);
|
|
9
|
+
var querystring = require('querystring');
|
|
10
|
+
var Url = require('url');
|
|
11
|
+
var zlib = require('zlib');
|
|
12
|
+
var buffer = require('buffer');
|
|
13
|
+
var net = require('net');
|
|
14
|
+
var http = require('http');
|
|
15
|
+
var https = require('https');
|
|
16
|
+
|
|
17
|
+
function sendMsg(process, msg) {
|
|
18
|
+
process.send(msg);
|
|
19
|
+
}
|
|
20
|
+
function sendError(process, e) {
|
|
21
|
+
const msg = {
|
|
22
|
+
error: {
|
|
23
|
+
message: e
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
if (typeof e === 'string') {
|
|
27
|
+
msg.error.message = e + '';
|
|
28
|
+
}
|
|
29
|
+
else if (e) {
|
|
30
|
+
Object.keys(e).forEach(key => {
|
|
31
|
+
try {
|
|
32
|
+
msg.error[key] = e[key] + '';
|
|
33
|
+
}
|
|
34
|
+
catch (idk) {
|
|
35
|
+
console.log(idk);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
sendMsg(process, msg);
|
|
40
|
+
}
|
|
41
|
+
function responseHeaders(headers) {
|
|
42
|
+
return Object.assign({}, DEFAULT_HEADERS, headers);
|
|
43
|
+
}
|
|
44
|
+
const DEFAULT_HEADERS = {
|
|
45
|
+
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
|
|
46
|
+
'Expires': '0',
|
|
47
|
+
'X-Powered-By': 'Rindo Dev Server',
|
|
48
|
+
'Access-Control-Allow-Origin': '*'
|
|
49
|
+
};
|
|
50
|
+
function getBrowserUrl(protocol, address, port, basePath, pathname) {
|
|
51
|
+
address = (address === `0.0.0.0`) ? `localhost` : address;
|
|
52
|
+
const portSuffix = (!port || port === 80 || port === 443) ? '' : (':' + port);
|
|
53
|
+
let path = basePath;
|
|
54
|
+
if (pathname.startsWith('/')) {
|
|
55
|
+
pathname = pathname.substring(1);
|
|
56
|
+
}
|
|
57
|
+
path += pathname;
|
|
58
|
+
protocol = protocol.replace(/\:/g, '');
|
|
59
|
+
return `${protocol}://${address}${portSuffix}${path}`;
|
|
60
|
+
}
|
|
61
|
+
function getDevServerClientUrl(devServerConfig, host) {
|
|
62
|
+
let address = devServerConfig.address;
|
|
63
|
+
let port = devServerConfig.port;
|
|
64
|
+
if (host) {
|
|
65
|
+
address = host;
|
|
66
|
+
port = null;
|
|
67
|
+
}
|
|
68
|
+
return getBrowserUrl(devServerConfig.protocol, address, port, devServerConfig.basePath, DEV_SERVER_URL);
|
|
69
|
+
}
|
|
70
|
+
function getContentType(devServerConfig, filePath) {
|
|
71
|
+
const last = filePath.replace(/^.*[/\\]/, '').toLowerCase();
|
|
72
|
+
const ext = last.replace(/^.*\./, '').toLowerCase();
|
|
73
|
+
const hasPath = last.length < filePath.length;
|
|
74
|
+
const hasDot = ext.length < last.length - 1;
|
|
75
|
+
return ((hasDot || !hasPath) && devServerConfig.contentTypes[ext]) || 'application/octet-stream';
|
|
76
|
+
}
|
|
77
|
+
function isHtmlFile(filePath) {
|
|
78
|
+
filePath = filePath.toLowerCase().trim();
|
|
79
|
+
return (filePath.endsWith('.html') || filePath.endsWith('.htm'));
|
|
80
|
+
}
|
|
81
|
+
function isCssFile(filePath) {
|
|
82
|
+
filePath = filePath.toLowerCase().trim();
|
|
83
|
+
return filePath.endsWith('.css');
|
|
84
|
+
}
|
|
85
|
+
const TXT_EXT = ['css', 'html', 'htm', 'js', 'json', 'svg', 'xml'];
|
|
86
|
+
function isSimpleText(filePath) {
|
|
87
|
+
const ext = filePath.toLowerCase().trim().split('.').pop();
|
|
88
|
+
return TXT_EXT.includes(ext);
|
|
89
|
+
}
|
|
90
|
+
function isDevClient(pathname) {
|
|
91
|
+
return pathname.startsWith(DEV_SERVER_URL);
|
|
92
|
+
}
|
|
93
|
+
function isOpenInEditor(pathname) {
|
|
94
|
+
return pathname === OPEN_IN_EDITOR_URL;
|
|
95
|
+
}
|
|
96
|
+
function isInitialDevServerLoad(pathname) {
|
|
97
|
+
return pathname === DEV_SERVER_INIT_URL;
|
|
98
|
+
}
|
|
99
|
+
function isDevServerClient(pathname) {
|
|
100
|
+
return pathname === DEV_SERVER_URL;
|
|
101
|
+
}
|
|
102
|
+
const DEV_SERVER_URL = '/~dev-server';
|
|
103
|
+
const DEV_SERVER_INIT_URL = `${DEV_SERVER_URL}-init`;
|
|
104
|
+
const OPEN_IN_EDITOR_URL = `${DEV_SERVER_URL}-open-in-editor`;
|
|
105
|
+
function shouldCompress(devServerConfig, req) {
|
|
106
|
+
if (!devServerConfig.gzip) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
if (req.method !== 'GET') {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const acceptEncoding = req.headers && req.headers['accept-encoding'];
|
|
113
|
+
if (typeof acceptEncoding !== 'string') {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (!acceptEncoding.includes('gzip')) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function serve500(devServerConfig, req, res, error) {
|
|
123
|
+
try {
|
|
124
|
+
res.writeHead(500, responseHeaders({
|
|
125
|
+
'Content-Type': 'text/plain'
|
|
126
|
+
}));
|
|
127
|
+
let errorMsg = '';
|
|
128
|
+
if (typeof error === 'string') {
|
|
129
|
+
errorMsg = error;
|
|
130
|
+
}
|
|
131
|
+
else if (error) {
|
|
132
|
+
if (error.message) {
|
|
133
|
+
errorMsg += error.message + '\n';
|
|
134
|
+
}
|
|
135
|
+
if (error.stack) {
|
|
136
|
+
errorMsg += error.stack + '\n';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
res.write(errorMsg);
|
|
140
|
+
res.end();
|
|
141
|
+
if (devServerConfig.logRequests) {
|
|
142
|
+
sendMsg(process, {
|
|
143
|
+
requestLog: {
|
|
144
|
+
method: req.method,
|
|
145
|
+
url: req.url,
|
|
146
|
+
status: 200
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
sendError(process, 'serve500: ' + e);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function serve404(devServerConfig, fs, req, res) {
|
|
157
|
+
try {
|
|
158
|
+
if (req.pathname === '/favicon.ico') {
|
|
159
|
+
try {
|
|
160
|
+
const defaultFavicon = path.join(devServerConfig.devServerDir, 'static', 'favicon.ico');
|
|
161
|
+
res.writeHead(200, responseHeaders({
|
|
162
|
+
'Content-Type': 'image/x-icon'
|
|
163
|
+
}));
|
|
164
|
+
fs.createReadStream(defaultFavicon).pipe(res);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
catch (e) { }
|
|
168
|
+
}
|
|
169
|
+
const content = [
|
|
170
|
+
'404 File Not Found',
|
|
171
|
+
'Url: ' + req.pathname,
|
|
172
|
+
'File: ' + req.filePath
|
|
173
|
+
].join('\n');
|
|
174
|
+
serve404Content(devServerConfig, req, res, content);
|
|
175
|
+
if (devServerConfig.logRequests) {
|
|
176
|
+
sendMsg(process, {
|
|
177
|
+
requestLog: {
|
|
178
|
+
method: req.method,
|
|
179
|
+
url: req.url,
|
|
180
|
+
status: 404
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (e) {
|
|
186
|
+
serve500(devServerConfig, req, res, e);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function serve404Content(devServerConfig, req, res, content) {
|
|
190
|
+
try {
|
|
191
|
+
const headers = responseHeaders({
|
|
192
|
+
'Content-Type': 'text/plain'
|
|
193
|
+
});
|
|
194
|
+
res.writeHead(404, headers);
|
|
195
|
+
res.write(content);
|
|
196
|
+
res.end();
|
|
197
|
+
}
|
|
198
|
+
catch (e) {
|
|
199
|
+
serve500(devServerConfig, req, res, e);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function serveFile(devServerConfig, fs, req, res) {
|
|
204
|
+
try {
|
|
205
|
+
if (isSimpleText(req.filePath)) {
|
|
206
|
+
// easy text file, use the internal cache
|
|
207
|
+
let content = await fs.readFile(req.filePath);
|
|
208
|
+
if (devServerConfig.websocket && isHtmlFile(req.filePath) && !isDevServerClient(req.pathname)) {
|
|
209
|
+
// auto inject our dev server script
|
|
210
|
+
content += getDevServerClientScript(devServerConfig, req);
|
|
211
|
+
}
|
|
212
|
+
else if (isCssFile(req.filePath)) {
|
|
213
|
+
content = updateStyleUrls(req.url, content);
|
|
214
|
+
}
|
|
215
|
+
if (shouldCompress(devServerConfig, req)) {
|
|
216
|
+
// let's gzip this well known web dev text file
|
|
217
|
+
res.writeHead(200, responseHeaders({
|
|
218
|
+
'Content-Type': getContentType(devServerConfig, req.filePath),
|
|
219
|
+
'Content-Encoding': 'gzip',
|
|
220
|
+
'Vary': 'Accept-Encoding'
|
|
221
|
+
}));
|
|
222
|
+
zlib.gzip(content, { level: 9 }, (_, data) => {
|
|
223
|
+
res.end(data);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
// let's not gzip this file
|
|
228
|
+
res.writeHead(200, responseHeaders({
|
|
229
|
+
'Content-Type': getContentType(devServerConfig, req.filePath),
|
|
230
|
+
'Content-Length': buffer.Buffer.byteLength(content, 'utf8')
|
|
231
|
+
}));
|
|
232
|
+
res.write(content);
|
|
233
|
+
res.end();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
// non-well-known text file or other file, probably best we use a stream
|
|
238
|
+
// but don't bother trying to gzip this file for the dev server
|
|
239
|
+
res.writeHead(200, responseHeaders({
|
|
240
|
+
'Content-Type': getContentType(devServerConfig, req.filePath),
|
|
241
|
+
'Content-Length': req.stats.size
|
|
242
|
+
}));
|
|
243
|
+
fs.createReadStream(req.filePath).pipe(res);
|
|
244
|
+
}
|
|
245
|
+
if (devServerConfig.logRequests) {
|
|
246
|
+
sendMsg(process, {
|
|
247
|
+
requestLog: {
|
|
248
|
+
method: req.method,
|
|
249
|
+
url: req.url,
|
|
250
|
+
status: 200
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
catch (e) {
|
|
256
|
+
serve500(devServerConfig, req, res, e);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function updateStyleUrls(cssUrl, oldCss) {
|
|
260
|
+
const parsedUrl = Url.parse(cssUrl);
|
|
261
|
+
const qs = querystring.parse(parsedUrl.query);
|
|
262
|
+
const versionId = qs['s-hmr'];
|
|
263
|
+
const hmrUrls = qs['s-hmr-urls'];
|
|
264
|
+
if (versionId && hmrUrls) {
|
|
265
|
+
hmrUrls.split(',').forEach(hmrUrl => {
|
|
266
|
+
urlVersionIds.set(hmrUrl, versionId);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
const reg = /url\((['"]?)(.*)\1\)/ig;
|
|
270
|
+
let result;
|
|
271
|
+
let newCss = oldCss;
|
|
272
|
+
while ((result = reg.exec(oldCss)) !== null) {
|
|
273
|
+
const oldUrl = result[2];
|
|
274
|
+
const parsedUrl = Url.parse(oldUrl);
|
|
275
|
+
const fileName = path__default.basename(parsedUrl.pathname);
|
|
276
|
+
const versionId = urlVersionIds.get(fileName);
|
|
277
|
+
if (!versionId) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const qs = querystring.parse(parsedUrl.query);
|
|
281
|
+
qs['s-hmr'] = versionId;
|
|
282
|
+
parsedUrl.search = querystring.stringify(qs);
|
|
283
|
+
const newUrl = Url.format(parsedUrl);
|
|
284
|
+
newCss = newCss.replace(oldUrl, newUrl);
|
|
285
|
+
}
|
|
286
|
+
return newCss;
|
|
287
|
+
}
|
|
288
|
+
const urlVersionIds = new Map();
|
|
289
|
+
function getDevServerClientScript(devServerConfig, req) {
|
|
290
|
+
const devServerClientUrl = getDevServerClientUrl(devServerConfig, req.host);
|
|
291
|
+
return `\n<iframe title="Rindo Dev Server Connector ⚡" src="${devServerClientUrl}" style="display:block;width:0;height:0;border:0"></iframe>`;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const openInEditorPath = path.join(__dirname, '..', 'sys', 'node', 'open-in-editor.js');
|
|
295
|
+
async function serveOpenInEditor(devServerConfig, fs, req, res) {
|
|
296
|
+
let status = 200;
|
|
297
|
+
const data = {};
|
|
298
|
+
try {
|
|
299
|
+
if (devServerConfig.editors.length > 0) {
|
|
300
|
+
await parseData(devServerConfig, fs, req, data);
|
|
301
|
+
await openInEditor(data);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
data.error = `no editors available`;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
catch (e) {
|
|
308
|
+
data.error = e + '';
|
|
309
|
+
status = 500;
|
|
310
|
+
}
|
|
311
|
+
res.writeHead(status, responseHeaders({
|
|
312
|
+
'Content-Type': 'application/json'
|
|
313
|
+
}));
|
|
314
|
+
res.write(JSON.stringify(data, null, 2));
|
|
315
|
+
res.end();
|
|
316
|
+
}
|
|
317
|
+
async function parseData(devServerConfig, fs, req, data) {
|
|
318
|
+
const query = Url.parse(req.url).query;
|
|
319
|
+
const qs = querystring.parse(query);
|
|
320
|
+
if (typeof qs.file !== 'string') {
|
|
321
|
+
data.error = `missing file`;
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
data.file = qs.file;
|
|
325
|
+
if (qs.line != null && !isNaN(qs.line)) {
|
|
326
|
+
data.line = parseInt(qs.line, 10);
|
|
327
|
+
}
|
|
328
|
+
if (typeof data.line !== 'number' || data.line < 1) {
|
|
329
|
+
data.line = 1;
|
|
330
|
+
}
|
|
331
|
+
if (qs.column != null && !isNaN(qs.column)) {
|
|
332
|
+
data.column = parseInt(qs.column, 10);
|
|
333
|
+
}
|
|
334
|
+
if (typeof data.column !== 'number' || data.column < 1) {
|
|
335
|
+
data.column = 1;
|
|
336
|
+
}
|
|
337
|
+
if (typeof qs.editor === 'string') {
|
|
338
|
+
qs.editor = qs.editor.trim().toLowerCase();
|
|
339
|
+
if (devServerConfig.editors.some(e => e.id === qs.editor)) {
|
|
340
|
+
data.editor = qs.editor;
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
data.error = `invalid editor: ${qs.editor}`;
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
data.editor = devServerConfig.editors[0].id;
|
|
349
|
+
}
|
|
350
|
+
try {
|
|
351
|
+
const stat = await fs.stat(data.file);
|
|
352
|
+
data.exists = stat.isFile();
|
|
353
|
+
}
|
|
354
|
+
catch (e) {
|
|
355
|
+
data.exists = false;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
async function openInEditor(data) {
|
|
359
|
+
if (!data.exists || data.error) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
try {
|
|
363
|
+
const opts = {
|
|
364
|
+
editor: data.editor
|
|
365
|
+
};
|
|
366
|
+
const oie = require(openInEditorPath);
|
|
367
|
+
const editor = oie.openInEditor.configure(opts, (err) => data.error = err + '');
|
|
368
|
+
if (data.error) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
data.open = `${data.file}:${data.line}:${data.column}`;
|
|
372
|
+
await editor.open(data.open);
|
|
373
|
+
}
|
|
374
|
+
catch (e) {
|
|
375
|
+
data.error = e + '';
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
async function getEditors() {
|
|
379
|
+
const editors = [];
|
|
380
|
+
try {
|
|
381
|
+
const oie = require(openInEditorPath);
|
|
382
|
+
await Promise.all(Object.keys(oie.editors).map(async (id) => {
|
|
383
|
+
const isSupported = await isEditorSupported(oie, id);
|
|
384
|
+
editors.push({
|
|
385
|
+
id: id,
|
|
386
|
+
priority: EDITOR_PRIORITY[id],
|
|
387
|
+
supported: isSupported
|
|
388
|
+
});
|
|
389
|
+
}));
|
|
390
|
+
}
|
|
391
|
+
catch (e) { }
|
|
392
|
+
return editors
|
|
393
|
+
.filter(e => e.supported)
|
|
394
|
+
.sort((a, b) => {
|
|
395
|
+
if (a.priority < b.priority)
|
|
396
|
+
return -1;
|
|
397
|
+
if (a.priority > b.priority)
|
|
398
|
+
return 1;
|
|
399
|
+
return 0;
|
|
400
|
+
}).map(e => {
|
|
401
|
+
return {
|
|
402
|
+
id: e.id,
|
|
403
|
+
name: EDITORS[e.id]
|
|
404
|
+
};
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
async function isEditorSupported(oie, editor) {
|
|
408
|
+
let isSupported = false;
|
|
409
|
+
try {
|
|
410
|
+
await oie.editors[editor].detect();
|
|
411
|
+
isSupported = true;
|
|
412
|
+
}
|
|
413
|
+
catch (e) { }
|
|
414
|
+
return isSupported;
|
|
415
|
+
}
|
|
416
|
+
const EDITORS = {
|
|
417
|
+
atom: 'Atom',
|
|
418
|
+
code: 'Code',
|
|
419
|
+
emacs: 'Emacs',
|
|
420
|
+
idea14ce: 'IDEA 14 Community Edition',
|
|
421
|
+
phpstorm: 'PhpStorm',
|
|
422
|
+
sublime: 'Sublime',
|
|
423
|
+
webstorm: 'WebStorm',
|
|
424
|
+
vim: 'Vim',
|
|
425
|
+
visualstudio: 'Visual Studio',
|
|
426
|
+
};
|
|
427
|
+
const EDITOR_PRIORITY = {
|
|
428
|
+
code: 1,
|
|
429
|
+
atom: 2,
|
|
430
|
+
sublime: 3,
|
|
431
|
+
visualstudio: 4,
|
|
432
|
+
idea14ce: 5,
|
|
433
|
+
webstorm: 6,
|
|
434
|
+
phpstorm: 7,
|
|
435
|
+
vim: 8,
|
|
436
|
+
emacs: 9,
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
async function serveDevClient(devServerConfig, fs, req, res) {
|
|
440
|
+
try {
|
|
441
|
+
if (isOpenInEditor(req.pathname)) {
|
|
442
|
+
return serveOpenInEditor(devServerConfig, fs, req, res);
|
|
443
|
+
}
|
|
444
|
+
if (isDevServerClient(req.pathname)) {
|
|
445
|
+
return serveDevClientScript(devServerConfig, fs, req, res);
|
|
446
|
+
}
|
|
447
|
+
if (isInitialDevServerLoad(req.pathname)) {
|
|
448
|
+
req.filePath = path__default.join(devServerConfig.devServerDir, 'templates', 'initial-load.html');
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
const staticFile = req.pathname.replace(DEV_SERVER_URL + '/', '');
|
|
452
|
+
req.filePath = path__default.join(devServerConfig.devServerDir, 'static', staticFile);
|
|
453
|
+
}
|
|
454
|
+
try {
|
|
455
|
+
req.stats = await fs.stat(req.filePath);
|
|
456
|
+
return serveFile(devServerConfig, fs, req, res);
|
|
457
|
+
}
|
|
458
|
+
catch (e) {
|
|
459
|
+
return serve404(devServerConfig, fs, req, res);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
catch (e) {
|
|
463
|
+
return serve500(devServerConfig, req, res, e);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
async function serveDevClientScript(devServerConfig, fs, req, res) {
|
|
467
|
+
const filePath = path__default.join(devServerConfig.devServerDir, 'static', 'dev-server-client.html');
|
|
468
|
+
let content = await fs.readFile(filePath);
|
|
469
|
+
const devClientConfig = {
|
|
470
|
+
basePath: devServerConfig.basePath,
|
|
471
|
+
editors: devServerConfig.editors,
|
|
472
|
+
reloadStrategy: devServerConfig.reloadStrategy
|
|
473
|
+
};
|
|
474
|
+
content = content.replace('window.__DEV_CLIENT_CONFIG__', JSON.stringify(devClientConfig));
|
|
475
|
+
res.writeHead(200, responseHeaders({
|
|
476
|
+
'Content-Type': 'text/html'
|
|
477
|
+
}));
|
|
478
|
+
res.write(content);
|
|
479
|
+
res.end();
|
|
480
|
+
if (devServerConfig.logRequests) {
|
|
481
|
+
sendMsg(process, {
|
|
482
|
+
requestLog: {
|
|
483
|
+
method: req.method,
|
|
484
|
+
url: req.url,
|
|
485
|
+
status: 200
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
async function serveDirectoryIndex(devServerConfig, fs, req, res) {
|
|
492
|
+
try {
|
|
493
|
+
const indexFilePath = path__default.join(req.filePath, 'index.html');
|
|
494
|
+
req.stats = await fs.stat(indexFilePath);
|
|
495
|
+
if (req.stats.isFile()) {
|
|
496
|
+
req.filePath = indexFilePath;
|
|
497
|
+
return serveFile(devServerConfig, fs, req, res);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
catch (e) { }
|
|
501
|
+
if (!req.pathname.endsWith('/')) {
|
|
502
|
+
if (devServerConfig.logRequests) {
|
|
503
|
+
sendMsg(process, {
|
|
504
|
+
requestLog: {
|
|
505
|
+
method: req.method,
|
|
506
|
+
url: req.url,
|
|
507
|
+
status: 302
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
res.writeHead(302, {
|
|
512
|
+
'location': req.pathname + '/'
|
|
513
|
+
});
|
|
514
|
+
return res.end();
|
|
515
|
+
}
|
|
516
|
+
try {
|
|
517
|
+
const dirItemNames = await fs.readdir(req.filePath);
|
|
518
|
+
try {
|
|
519
|
+
const dirTemplatePath = path__default.join(devServerConfig.devServerDir, 'templates', 'directory-index.html');
|
|
520
|
+
const dirTemplate = await fs.readFile(dirTemplatePath);
|
|
521
|
+
const files = await getFiles(fs, req.filePath, req.pathname, dirItemNames);
|
|
522
|
+
const templateHtml = dirTemplate
|
|
523
|
+
.replace('{{title}}', getTitle(req.pathname))
|
|
524
|
+
.replace('{{nav}}', getName(req.pathname))
|
|
525
|
+
.replace('{{files}}', files);
|
|
526
|
+
res.writeHead(200, responseHeaders({
|
|
527
|
+
'Content-Type': 'text/html',
|
|
528
|
+
'X-Directory-Index': req.pathname
|
|
529
|
+
}));
|
|
530
|
+
res.write(templateHtml);
|
|
531
|
+
res.end();
|
|
532
|
+
if (devServerConfig.logRequests) {
|
|
533
|
+
sendMsg(process, {
|
|
534
|
+
requestLog: {
|
|
535
|
+
method: req.method,
|
|
536
|
+
url: req.url,
|
|
537
|
+
status: 200
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
catch (e) {
|
|
543
|
+
serve500(devServerConfig, req, res, e);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
catch (e) {
|
|
547
|
+
serve404(devServerConfig, fs, req, res);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
async function getFiles(fs, filePath, urlPathName, dirItemNames) {
|
|
551
|
+
const items = await getDirectoryItems(fs, filePath, urlPathName, dirItemNames);
|
|
552
|
+
if (urlPathName !== '/') {
|
|
553
|
+
items.unshift({
|
|
554
|
+
isDirectory: true,
|
|
555
|
+
pathname: '../',
|
|
556
|
+
name: '..'
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
return items
|
|
560
|
+
.map(item => {
|
|
561
|
+
return (`
|
|
562
|
+
<li class="${item.isDirectory ? 'directory' : 'file'}">
|
|
563
|
+
<a href="${item.pathname}">
|
|
564
|
+
<span class="icon"></span>
|
|
565
|
+
<span>${item.name}</span>
|
|
566
|
+
</a>
|
|
567
|
+
</li>`);
|
|
568
|
+
})
|
|
569
|
+
.join('');
|
|
570
|
+
}
|
|
571
|
+
async function getDirectoryItems(fs, filePath, urlPathName, dirItemNames) {
|
|
572
|
+
const items = await Promise.all(dirItemNames.map(async (dirItemName) => {
|
|
573
|
+
const absPath = path__default.join(filePath, dirItemName);
|
|
574
|
+
const stats = await fs.stat(absPath);
|
|
575
|
+
const item = {
|
|
576
|
+
name: dirItemName,
|
|
577
|
+
pathname: Url.resolve(urlPathName, dirItemName),
|
|
578
|
+
isDirectory: stats.isDirectory()
|
|
579
|
+
};
|
|
580
|
+
return item;
|
|
581
|
+
}));
|
|
582
|
+
return items;
|
|
583
|
+
}
|
|
584
|
+
function getTitle(pathName) {
|
|
585
|
+
return pathName;
|
|
586
|
+
}
|
|
587
|
+
function getName(pathName) {
|
|
588
|
+
const dirs = pathName.split('/');
|
|
589
|
+
dirs.pop();
|
|
590
|
+
let url = '';
|
|
591
|
+
return dirs.map((dir, index) => {
|
|
592
|
+
url += dir + '/';
|
|
593
|
+
const text = (index === 0 ? `~` : dir);
|
|
594
|
+
return `<a href="${url}">${text}</a>`;
|
|
595
|
+
}).join('<span>/</span>') + '<span>/</span>';
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function createRequestHandler(devServerConfig, fs) {
|
|
599
|
+
return async function (incomingReq, res) {
|
|
600
|
+
try {
|
|
601
|
+
const req = normalizeHttpRequest(devServerConfig, incomingReq);
|
|
602
|
+
if (req.url === '') {
|
|
603
|
+
res.writeHead(302, { 'location': '/' });
|
|
604
|
+
if (devServerConfig.logRequests) {
|
|
605
|
+
sendMsg(process, {
|
|
606
|
+
requestLog: {
|
|
607
|
+
method: req.method,
|
|
608
|
+
url: req.url,
|
|
609
|
+
status: 302
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
return res.end();
|
|
614
|
+
}
|
|
615
|
+
if (isDevClient(req.pathname) && devServerConfig.websocket) {
|
|
616
|
+
return serveDevClient(devServerConfig, fs, req, res);
|
|
617
|
+
}
|
|
618
|
+
if (!req.url.startsWith(devServerConfig.basePath)) {
|
|
619
|
+
if (devServerConfig.logRequests) {
|
|
620
|
+
sendMsg(process, {
|
|
621
|
+
requestLog: {
|
|
622
|
+
method: req.method,
|
|
623
|
+
url: req.url,
|
|
624
|
+
status: 404
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
return serve404Content(devServerConfig, req, res, `404 File Not Found, base path: ${devServerConfig.basePath}`);
|
|
629
|
+
}
|
|
630
|
+
try {
|
|
631
|
+
req.stats = await fs.stat(req.filePath);
|
|
632
|
+
if (req.stats.isFile()) {
|
|
633
|
+
return serveFile(devServerConfig, fs, req, res);
|
|
634
|
+
}
|
|
635
|
+
if (req.stats.isDirectory()) {
|
|
636
|
+
return serveDirectoryIndex(devServerConfig, fs, req, res);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
catch (e) { }
|
|
640
|
+
if (isValidHistoryApi(devServerConfig, req)) {
|
|
641
|
+
try {
|
|
642
|
+
const indexFilePath = path__default.join(devServerConfig.root, devServerConfig.historyApiFallback.index);
|
|
643
|
+
req.stats = await fs.stat(indexFilePath);
|
|
644
|
+
if (req.stats.isFile()) {
|
|
645
|
+
req.filePath = indexFilePath;
|
|
646
|
+
return serveFile(devServerConfig, fs, req, res);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
catch (e) { }
|
|
650
|
+
}
|
|
651
|
+
return serve404(devServerConfig, fs, req, res);
|
|
652
|
+
}
|
|
653
|
+
catch (e) {
|
|
654
|
+
return serve500(devServerConfig, incomingReq, res, e);
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
function normalizeHttpRequest(devServerConfig, incomingReq) {
|
|
659
|
+
const req = {
|
|
660
|
+
method: (incomingReq.method || 'GET').toUpperCase(),
|
|
661
|
+
headers: incomingReq.headers,
|
|
662
|
+
acceptHeader: (incomingReq.headers && typeof incomingReq.headers.accept === 'string' && incomingReq.headers.accept) || '',
|
|
663
|
+
url: (incomingReq.url || '').trim() || '',
|
|
664
|
+
host: (incomingReq.headers && typeof incomingReq.headers.host === 'string' && incomingReq.headers.host) || null
|
|
665
|
+
};
|
|
666
|
+
const parsedUrl = Url.parse(req.url);
|
|
667
|
+
const parts = (parsedUrl.pathname || '').replace(/\\/g, '/').split('/');
|
|
668
|
+
req.pathname = parts.map(part => decodeURIComponent(part)).join('/');
|
|
669
|
+
if (req.pathname.length > 0 && !isDevClient(req.pathname)) {
|
|
670
|
+
req.pathname = '/' + req.pathname.substring(devServerConfig.basePath.length);
|
|
671
|
+
}
|
|
672
|
+
req.filePath = utils.normalizePath(path__default.normalize(path__default.join(devServerConfig.root, path__default.relative('/', req.pathname))));
|
|
673
|
+
return req;
|
|
674
|
+
}
|
|
675
|
+
function isValidHistoryApi(devServerConfig, req) {
|
|
676
|
+
if (!devServerConfig.historyApiFallback) {
|
|
677
|
+
return false;
|
|
678
|
+
}
|
|
679
|
+
if (req.method !== 'GET') {
|
|
680
|
+
return false;
|
|
681
|
+
}
|
|
682
|
+
if (!req.acceptHeader.includes('text/html')) {
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
if (!devServerConfig.historyApiFallback.disableDotRule && req.pathname.includes('.')) {
|
|
686
|
+
return false;
|
|
687
|
+
}
|
|
688
|
+
return true;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
async function findClosestOpenPort(host, port) {
|
|
692
|
+
async function t(portToCheck) {
|
|
693
|
+
const isTaken = await isPortTaken(host, portToCheck);
|
|
694
|
+
if (!isTaken) {
|
|
695
|
+
return portToCheck;
|
|
696
|
+
}
|
|
697
|
+
return t(portToCheck + 1);
|
|
698
|
+
}
|
|
699
|
+
return t(port);
|
|
700
|
+
}
|
|
701
|
+
function isPortTaken(host, port) {
|
|
702
|
+
return new Promise((resolve, reject) => {
|
|
703
|
+
const tester = net.createServer()
|
|
704
|
+
.once('error', () => {
|
|
705
|
+
resolve(true);
|
|
706
|
+
})
|
|
707
|
+
.once('listening', () => {
|
|
708
|
+
tester.once('close', () => {
|
|
709
|
+
resolve(false);
|
|
710
|
+
})
|
|
711
|
+
.close();
|
|
712
|
+
})
|
|
713
|
+
.on('error', (err) => {
|
|
714
|
+
reject(err);
|
|
715
|
+
})
|
|
716
|
+
.listen(port, host);
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
async function createHttpServer(devServerConfig, fs, destroys) {
|
|
721
|
+
// figure out the port to be listening on
|
|
722
|
+
// by figuring out the first one available
|
|
723
|
+
devServerConfig.port = await findClosestOpenPort(devServerConfig.address, devServerConfig.port);
|
|
724
|
+
// create our request handler
|
|
725
|
+
const reqHandler = createRequestHandler(devServerConfig, fs);
|
|
726
|
+
const credentials = devServerConfig.https;
|
|
727
|
+
let server = credentials ? https.createServer(credentials, reqHandler) : http.createServer(reqHandler);
|
|
728
|
+
destroys.push(() => {
|
|
729
|
+
// close down the serve on destroy
|
|
730
|
+
server.close();
|
|
731
|
+
server = null;
|
|
732
|
+
});
|
|
733
|
+
return server;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
const WebSocket = require('../sys/node/websocket').WebSocket;
|
|
737
|
+
function createWebSocket(process, httpServer, destroys) {
|
|
738
|
+
const wsConfig = {
|
|
739
|
+
server: httpServer
|
|
740
|
+
};
|
|
741
|
+
const wsServer = new WebSocket.Server(wsConfig);
|
|
742
|
+
function heartbeat() {
|
|
743
|
+
this.isAlive = true;
|
|
744
|
+
}
|
|
745
|
+
wsServer.on('connection', (ws) => {
|
|
746
|
+
ws.on('message', (data) => {
|
|
747
|
+
// the server process has received a message from the browser
|
|
748
|
+
// pass the message received from the browser to the main cli process
|
|
749
|
+
process.send(JSON.parse(data.toString()));
|
|
750
|
+
});
|
|
751
|
+
ws.isAlive = true;
|
|
752
|
+
ws.on('pong', heartbeat);
|
|
753
|
+
});
|
|
754
|
+
const pingInternval = setInterval(() => {
|
|
755
|
+
wsServer.clients.forEach((ws) => {
|
|
756
|
+
if (!ws.isAlive) {
|
|
757
|
+
return ws.close(1000);
|
|
758
|
+
}
|
|
759
|
+
ws.isAlive = false;
|
|
760
|
+
ws.ping(utils.noop);
|
|
761
|
+
});
|
|
762
|
+
}, 10000);
|
|
763
|
+
function onMessageFromCli(msg) {
|
|
764
|
+
// the server process has received a message from the cli's main thread
|
|
765
|
+
// pass the data to each web socket for each browser/tab connected
|
|
766
|
+
if (msg) {
|
|
767
|
+
const data = JSON.stringify(msg);
|
|
768
|
+
wsServer.clients.forEach(ws => {
|
|
769
|
+
if (ws.readyState === ws.OPEN) {
|
|
770
|
+
ws.send(data);
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
process.addListener('message', onMessageFromCli);
|
|
776
|
+
destroys.push(() => {
|
|
777
|
+
clearInterval(pingInternval);
|
|
778
|
+
wsServer.clients.forEach(ws => {
|
|
779
|
+
ws.close(1000);
|
|
780
|
+
});
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/*
|
|
785
|
+
* exit
|
|
786
|
+
* https://github.com/cowboy/node-exit
|
|
787
|
+
*
|
|
788
|
+
* Copyright (c) 2013 "Cowboy" Ben Alman
|
|
789
|
+
* Licensed under the MIT license.
|
|
790
|
+
*/
|
|
791
|
+
|
|
792
|
+
var exit = function exit(exitCode, streams) {
|
|
793
|
+
if (!streams) { streams = [process.stdout, process.stderr]; }
|
|
794
|
+
var drainCount = 0;
|
|
795
|
+
// Actually exit if all streams are drained.
|
|
796
|
+
function tryToExit() {
|
|
797
|
+
if (drainCount === streams.length) {
|
|
798
|
+
process.exit(exitCode);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
streams.forEach(function(stream) {
|
|
802
|
+
// Count drained streams now, but monitor non-drained streams.
|
|
803
|
+
if (stream.bufferSize === 0) {
|
|
804
|
+
drainCount++;
|
|
805
|
+
} else {
|
|
806
|
+
stream.write('', 'utf-8', function() {
|
|
807
|
+
drainCount++;
|
|
808
|
+
tryToExit();
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
// Prevent further writing.
|
|
812
|
+
stream.write = function() {};
|
|
813
|
+
});
|
|
814
|
+
// If all streams were already drained, exit now.
|
|
815
|
+
tryToExit();
|
|
816
|
+
// In Windows, when run as a Node.js child process, a script utilizing
|
|
817
|
+
// this library might just exit with a 0 exit code, regardless. This code,
|
|
818
|
+
// despite the fact that it looks a bit crazy, appears to fix that.
|
|
819
|
+
process.on('exit', function() {
|
|
820
|
+
process.exit(exitCode);
|
|
821
|
+
});
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
async function startDevServerWorker(process, devServerConfig, fs) {
|
|
825
|
+
try {
|
|
826
|
+
const destroys = [];
|
|
827
|
+
devServerConfig.editors = await getEditors();
|
|
828
|
+
// create the http server listening for and responding to requests from the browser
|
|
829
|
+
let httpServer = await createHttpServer(devServerConfig, fs, destroys);
|
|
830
|
+
if (devServerConfig.websocket) {
|
|
831
|
+
// upgrade web socket requests the server receives
|
|
832
|
+
createWebSocket(process, httpServer, destroys);
|
|
833
|
+
}
|
|
834
|
+
// start listening!
|
|
835
|
+
httpServer.listen(devServerConfig.port, devServerConfig.address);
|
|
836
|
+
// have the server worker send a message to the main cli
|
|
837
|
+
// process that the server has successfully started up
|
|
838
|
+
sendMsg(process, {
|
|
839
|
+
serverStated: {
|
|
840
|
+
browserUrl: getBrowserUrl(devServerConfig.protocol, devServerConfig.address, devServerConfig.port, devServerConfig.basePath, '/'),
|
|
841
|
+
initialLoadUrl: getBrowserUrl(devServerConfig.protocol, devServerConfig.address, devServerConfig.port, devServerConfig.basePath, devServerConfig.initialLoadUrl || DEV_SERVER_INIT_URL)
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
const closeServer = () => {
|
|
845
|
+
// probably recived a SIGINT message from the parent cli process
|
|
846
|
+
// let's do our best to gracefully close everything down first
|
|
847
|
+
destroys.forEach(destroy => {
|
|
848
|
+
destroy();
|
|
849
|
+
});
|
|
850
|
+
destroys.length = 0;
|
|
851
|
+
httpServer = null;
|
|
852
|
+
setTimeout(() => {
|
|
853
|
+
exit(0);
|
|
854
|
+
}, 5000).unref();
|
|
855
|
+
process.removeAllListeners('message');
|
|
856
|
+
};
|
|
857
|
+
process.once('SIGINT', closeServer);
|
|
858
|
+
}
|
|
859
|
+
catch (e) {
|
|
860
|
+
sendError(process, e);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
async function startServer(devServerConfig) {
|
|
865
|
+
// received a message from main to start the server
|
|
866
|
+
try {
|
|
867
|
+
const fs = new node.NodeFs(process);
|
|
868
|
+
devServerConfig.contentTypes = await loadContentTypes(fs);
|
|
869
|
+
startDevServerWorker(process, devServerConfig, fs);
|
|
870
|
+
}
|
|
871
|
+
catch (e) {
|
|
872
|
+
sendError(process, e);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
async function loadContentTypes(fs) {
|
|
876
|
+
const contentTypePath = path__default.join(__dirname, 'content-type-db.json');
|
|
877
|
+
const contentTypeJson = await fs.readFile(contentTypePath);
|
|
878
|
+
return JSON.parse(contentTypeJson);
|
|
879
|
+
}
|
|
880
|
+
process.on('message', (msg) => {
|
|
881
|
+
if (msg.startServer) {
|
|
882
|
+
startServer(msg.startServer);
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
process.on('unhandledRejection', (e) => {
|
|
886
|
+
console.log(e);
|
|
887
|
+
});
|