From 7eb6d85d4177e34d3ff2b78ee4f2ff719fc508d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8B=92=E7=8B=92=E7=A5=9E?= Date: Mon, 16 Nov 2020 15:43:32 +0800 Subject: [PATCH] Migrate project (#483) * chore: update commitlint * chore: update commitlint * chore: remove image-source-loader * chore: update README * chore: update README * chore: update link * chore: update docs link * chore: update gitter link * chore: test case * chore: change entry --- .eslintignore | 37 +- .eslintrc.js | 17 +- .github/CONTRIBUTING.md | 93 + .github/GIT_COMMIT_SPECIFIC.md | 39 + .github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md | 22 + .github/ISSUE_TEMPLATE/bug_report_cn.md | 38 + .github/workflows/auto-publisher.yml | 10 +- .github/workflows/beta-publisher.yml | 24 + .github/workflows/ci.yml | 28 +- .gitignore | 58 +- .prettierignore | 8 + .prettierrc.js | 3 + CHANGELOG.md | 32 + README.md | 143 +- README_zh-CN.md | 116 + babel.config.js | 19 - codecov.yml | 16 + commitlint.config.js | 6 +- examples/rax-app-ts/README.md | 15 - examples/rax-app-ts/build.json | 13 - examples/rax-app-ts/src/app.ts | 4 - .../src/components/LogoCss/index.tsx | 22 - .../src/components/LogoCssModule/index.tsx | 22 - .../src/components/LogoLess/index.less | 3 - .../src/components/LogoLess/index.tsx | 25 - .../src/components/LogoLessModule/index.tsx | 25 - .../src/components/LogoSass/index.scss | 9 - .../src/components/LogoSass/index.tsx | 22 - .../src/components/LogoSassModule/index.tsx | 21 - examples/rax-app-ts/src/pages/Home/index.tsx | 23 - examples/rax-app-ts/src/typings.d.ts | 12 - examples/rax-component-js/README.md | 37 - examples/rax-component-js/build.json | 12 - examples/rax-component-js/demo/advance.md | 15 - examples/rax-component-js/demo/basic.md | 15 - examples/rax-component-js/package.json | 41 - examples/rax-component-js/src/index.jsx | 13 - examples/rax-component-ts/README.md | 37 - examples/rax-component-ts/build.json | 12 - examples/rax-component-ts/demo/advance.md | 15 - examples/rax-component-ts/demo/basic.md | 15 - examples/rax-component-ts/package.json | 44 - examples/rax-component-ts/src/index.tsx | 17 - examples/rax-component-ts/tsconfig.json | 27 - examples/with-rax-miniapp-compile/README.md | 3 + examples/with-rax-miniapp-compile/build.json | 6 + .../with-rax-miniapp-compile/package.json | 22 + .../with-rax-miniapp-compile/src/app.json | 15 + examples/with-rax-miniapp-compile/src/app.tsx | 17 + .../src/components/Logo/index.css} | 5 +- .../src/components/Logo/index.tsx | 23 + .../src/document/index.jsx | 22 + .../src/miniapp-native/rax.png | Bin 0 -> 57959 bytes .../src/pages/About/index.css | 16 + .../src/pages/About/index.tsx | 31 + .../src/pages/Home/index.css | 16 + .../src/pages/Home/index.tsx | 33 + .../tsconfig.json | 14 +- examples/with-rax-mpa/README.md | 3 + examples/with-rax-mpa/build.json | 13 + examples/with-rax-mpa/package.json | 22 + examples/with-rax-mpa/public/rax.png | Bin 0 -> 57959 bytes examples/with-rax-mpa/src/app.json | 18 + examples/with-rax-mpa/src/app.tsx | 29 + .../src/components/Logo/index.css} | 6 +- .../src/components/Logo/index.tsx | 21 + examples/with-rax-mpa/src/document/index.jsx | 30 + .../src/pages/About}/app.json | 2 +- examples/with-rax-mpa/src/pages/About/app.ts | 19 + .../with-rax-mpa/src/pages/About/index.css | 16 + .../with-rax-mpa/src/pages/About/index.tsx | 17 + .../with-rax-mpa/src/pages/Home/index.css | 16 + .../with-rax-mpa/src/pages/Home/index.tsx | 39 + examples/with-rax-mpa/tsconfig.json | 20 + examples/with-rax-store/README.md | 3 + examples/with-rax-store/build.json | 4 + .../package.json | 19 +- examples/with-rax-store/src/app.json | 34 + examples/with-rax-store/src/app.tsx | 13 + .../src/components/Logo/index.css} | 6 +- .../src/components/Logo/index.tsx | 16 + .../src/document/index.tsx} | 2 +- examples/with-rax-store/src/models/counter.ts | 25 + .../with-rax-store/src/pages/About/index.css | 16 + .../with-rax-store/src/pages/About/index.tsx | 32 + .../with-rax-store/src/pages/Home/index.css | 16 + .../with-rax-store/src/pages/Home/index.tsx | 33 + .../src/pages/Home/models/counter.ts | 25 + .../with-rax-store/src/pages/Home/store.ts | 6 + examples/with-rax-store/src/store.ts | 5 + examples/with-rax-store/tsconfig.json | 20 + examples/with-rax/README.md | 3 + examples/with-rax/build.json | 3 + examples/with-rax/package.json | 22 + examples/with-rax/public/rax.png | Bin 0 -> 57959 bytes examples/with-rax/src/app.json | 15 + examples/with-rax/src/app.tsx | 28 + .../src/components/BuggyCounter/index.tsx | 27 + .../src/components/Logo}/index.css | 5 +- .../with-rax/src/components/Logo/index.tsx | 21 + examples/with-rax/src/document/index.jsx | 22 + examples/with-rax/src/miniapp-native/rax.png | Bin 0 -> 57959 bytes examples/with-rax/src/pages/About/index.css | 16 + examples/with-rax/src/pages/About/index.tsx | 34 + examples/with-rax/src/pages/Home/index.css | 16 + examples/with-rax/src/pages/Home/index.tsx | 42 + examples/with-rax/tsconfig.json | 20 + jest.config.js | 23 +- lerna.json | 13 +- package.json | 87 +- .../package.json | 2 +- .../src/__tests__/{index.js => index.ts} | 12 +- .../src/__tests__/{module.js => module.ts} | 12 +- .../src/{constants.js => constants.ts} | 0 .../src/{index.js => index.ts} | 41 +- .../tsconfig.json | 8 + .../package.json | 2 +- .../src/__tests__/index.js | 14 +- .../src/index.js | 59 +- .../package.json | 46 - .../src/build.js | 28 - .../src/config/demo.html | 11 - .../src/config/getBaseWebpack.js | 129 - .../src/config/getDev.js | 71 - .../src/config/getDistConfig.js | 74 - .../src/config/portal.html | 373 - .../src/config/template/portal.hbs | 169 - .../src/config/utils/generatePortalJs.js | 38 - .../src/config/utils/getBuildTargets.js | 16 - .../src/config/utils/getDemos.js | 44 - .../src/config/utils/parseMarkdown.js | 119 - .../build-plugin-multi-demo-portal/src/dev.js | 56 - .../src/index.js | 27 - .../src/loaders/MarkdownLoader/index.js | 12 - packages/build-plugin-rax-app/package.json | 74 - packages/build-plugin-rax-app/src/build.js | 120 - .../src/config/getWebpackBase.js | 84 - .../src/config/kraken/getBase.js | 13 - .../src/config/kraken/setDev.js | 16 - .../src/config/miniapp/compile/getBase.js | 40 - .../src/config/miniapp/runtime/getBase.js | 33 - .../src/config/processRelativePublicPath.js | 44 - .../src/config/setEntry.js | 33 - .../src/config/user/keys/alias.js | 21 - .../src/config/user/keys/analyzer.js | 13 - .../src/config/user/keys/devPublicPath.js | 11 - .../src/config/user/keys/devServer.js | 20 - .../src/config/user/keys/hash.js | 32 - .../src/config/user/keys/inlineStyle.js | 161 - .../src/config/user/keys/outputDir.js | 10 - .../src/config/user/keys/publicPath.js | 11 - .../src/config/user/keys/sourceMap.js | 18 - .../src/config/user/keys/stats.js | 12 - .../src/config/user/setConfig.js | 16 - .../src/config/web/getBase.js | 24 - .../src/config/weex/getBase.js | 16 - .../src/config/weex/setDev.js | 2 - packages/build-plugin-rax-app/src/dev.js | 164 - packages/build-plugin-rax-app/src/index.js | 57 - .../src/loaders/AppConfigLoader/getDepPath.js | 17 - .../src/loaders/AppConfigLoader/index.js | 102 - .../src/plugins/DocumentPlugin/config.js | 52 - packages/build-plugin-rax-block/README.md | 14 - packages/build-plugin-rax-block/package.json | 15 - packages/build-plugin-rax-block/src/index.js | 31 - packages/build-plugin-rax-component/README.md | 13 - .../build-plugin-rax-component/package.json | 61 - .../build-plugin-rax-component/src/build.js | 108 - .../src/config/demo.html | 11 - .../src/config/getBaseWebpack.js | 110 - .../src/config/getDemos.js | 58 - .../src/config/getDistConfig.js | 103 - .../src/config/getES6Config.js | 8 - .../src/config/getUMDConfig.js | 14 - .../src/config/miniapp/getBase.js | 22 - .../src/config/miniapp/getOutputPath.js | 17 - .../src/config/node/getDev.js | 119 - .../src/config/node/ignoreLoader.js | 4 - .../src/config/parseMarkdown.js | 63 - .../src/config/user/default.config.js | 16 - .../src/config/user/keys/devPublicPath.js | 11 - .../src/config/user/keys/devServer.js | 18 - .../src/config/user/keys/mockNodeEnv.js | 30 - .../src/config/user/keys/outputDir.js | 12 - .../src/config/user/keys/publicPath.js | 11 - .../src/config/user/setConfig.js | 16 - .../src/config/web/getDev.js | 112 - .../src/config/weex/getDev.js | 37 - .../src/constants.js | 7 - .../build-plugin-rax-component/src/dev.js | 134 - .../src/gulp/compile.js | 8 - .../src/gulp/filePatterns.js | 6 - .../src/gulp/gulpfile.js | 139 - .../src/gulp/params.js | 2 - .../build-plugin-rax-component/src/index.js | 29 - .../src/loaders/MarkdownLoader/index.js | 12 - .../src/plugins/WeexFrameworkBannerPlugin.js | 65 - .../src/watchLib.js | 9 - .../build-plugin-rax-miniapp-plugin/README.md | 13 - .../package.json | 42 - .../src/build.js | 54 - .../src/config/getBase.js | 188 - .../src/config/getOutputPath.js | 18 - .../src/config/getPluginConfig.js | 7 - .../src/config/platformConfig.js | 38 - .../src/config/setEntry.js | 54 - .../src/config/targetPlatformMap.js | 6 - .../src/config/user/keys/alias.js | 21 - .../src/config/user/keys/devServer.js | 18 - .../src/config/user/keys/outputDir.js | 10 - .../src/config/user/setConfig.js | 16 - .../src/constants.js | 4 - .../src/dev.js | 67 - .../src/index.js | 52 - .../src/plugins/miniapp/CopyJsx2mpRuntime.js | 63 - .../src/plugins/miniapp/CopyPublicFile.js | 41 - .../src/plugins/miniapp/GenerateAppCss.js | 32 - .../plugins/miniapp/ModifyOutputFileSystem.js | 7 - .../src/plugins/miniapp/ProcessPluginJson.js | 48 - .../build-plugin-rax-multi-pages/README.md | 35 - .../build-plugin-rax-multi-pages/package.json | 14 - .../build-plugin-rax-multi-pages/src/index.js | 60 - packages/build-plugin-rax-ssr/README.md | 15 - packages/build-plugin-rax-ssr/package.json | 18 - packages/build-plugin-rax-ssr/src/index.js | 44 - .../src/ssr/entryLoader.js | 136 - .../src/ssr/entryPlugin.js | 57 - .../build-plugin-rax-ssr/src/ssr/getBase.js | 65 - .../src/ssr/getEntryName.js | 13 - .../build-plugin-rax-ssr/src/ssr/setBuild.js | 3 - .../build-plugin-rax-ssr/src/ssr/setDev.js | 63 - .../build-plugin-rax-ssr/src/web/setDev.js | 15 - packages/build-plugin-rax-theme/README.md | 13 - packages/build-plugin-rax-theme/package.json | 14 - packages/build-plugin-rax-theme/src/index.js | 26 - packages/create-rax/bin/create.js | 8 +- packages/error-stack-tracey/package.json | 2 +- packages/error-stack-tracey/src/index.js | 3 +- packages/eslint-config-rax/README.md | 37 - packages/eslint-config-rax/index.js | 9 - packages/eslint-config-rax/package.json | 28 - packages/eslint-config-rax/rules/base.js | 167 - packages/eslint-config-rax/rules/globals.js | 26 - packages/eslint-config-rax/rules/react.js | 54 - .../eslint-config-rax/rules/typescript.js | 85 - packages/eslint-plugin-module/README.md | 47 - packages/eslint-plugin-module/package.json | 27 - packages/eslint-plugin-module/src/index.js | 7 - .../src/rules/no-implicit-dependencies.js | 259 - packages/image-source-loader/README.md | 28 - packages/image-source-loader/mimes.json | 62 - packages/image-source-loader/package.json | 25 - .../src/__mocks__/one-pixel-png.js | 2 - .../src/__tests__/index.js | 58 - packages/image-source-loader/src/index.js | 28 - packages/jsx2mp-cli/.gitignore | 1 - packages/jsx2mp-cli/.npmignore | 7 - packages/jsx2mp-cli/README.md | 32 - packages/jsx2mp-cli/__tests__/component.js | 56 - packages/jsx2mp-cli/bin/jsx2mp-build.js | 36 - packages/jsx2mp-cli/bin/jsx2mp-start.js | 37 - packages/jsx2mp-cli/bin/jsx2mp.js | 19 - packages/jsx2mp-cli/checkPkgVersion.js | 28 - packages/jsx2mp-cli/default.js | 7 - packages/jsx2mp-cli/demo/assets/rax.png | Bin 916 -> 0 bytes packages/jsx2mp-cli/demo/component.js | 17 - packages/jsx2mp-cli/demo/package.json | 11 - packages/jsx2mp-cli/getWebpackConfig.js | 214 - packages/jsx2mp-cli/index.js | 189 - packages/jsx2mp-cli/package.json | 46 - packages/jsx2mp-cli/plugins/runtime.js | 40 - packages/jsx2mp-cli/utils/file.js | 59 - packages/jsx2mp-cli/utils/log.js | 26 - packages/jsx2mp-cli/utils/moduleResolve.js | 120 - packages/jsx2mp-cli/utils/platformConfig.js | 33 - packages/jsx2mp-cli/utils/removeExt.js | 8 - packages/jsx2mp-cli/utils/spinner.js | 18 - packages/jsx2mp-loader/package.json | 37 - packages/jsx2mp-loader/src/app-loader.js | 96 - .../src/babel-plugin-rename-import.js | 181 - packages/jsx2mp-loader/src/cached.js | 7 - .../jsx2mp-loader/src/component-loader.js | 193 - packages/jsx2mp-loader/src/constants.js | 5 - packages/jsx2mp-loader/src/defaultStyle.js | 14 - packages/jsx2mp-loader/src/file-loader.js | 19 - packages/jsx2mp-loader/src/output.js | 244 - packages/jsx2mp-loader/src/page-loader.js | 197 - packages/jsx2mp-loader/src/script-loader.js | 291 - packages/jsx2mp-loader/src/styleProcessor.js | 64 - .../jsx2mp-loader/src/utils/addSourceMap.js | 11 - packages/jsx2mp-loader/src/utils/dce.js | 47 - .../src/utils/getAliasCorrespondingValue.js | 56 - .../src/utils/isMiniappComponent.js | 15 - .../jsx2mp-loader/src/utils/judgeModule.js | 48 - .../jsx2mp-loader/src/utils/minifyCode.js | 46 - .../jsx2mp-loader/src/utils/parseRequest.js | 26 - .../jsx2mp-loader/src/utils/pathHelper.js | 117 - packages/miniapp-builder-shared/README.md | 24 - packages/miniapp-builder-shared/package.json | 27 - .../src/filterNativePages.js | 25 - .../src/getAppConfig.js | 56 - .../src/getOutputPath.js | 11 - packages/miniapp-builder-shared/src/index.js | 13 - .../miniapp-builder-shared/src/pathHelper.js | 150 - .../miniapp-builder-shared/src/platformMap.js | 36 - .../src/utils/constants.js | 6 - .../src/utils/getRouteName.js | 27 - packages/miniapp-compile-config/README.md | 56 - packages/miniapp-compile-config/package.json | 42 - packages/miniapp-compile-config/src/index.js | 2 - .../src/plugins/CopyJsx2mpRuntime.js | 65 - .../src/plugins/CopyPublicFile.js | 57 - .../src/plugins/ModifyOutputFileSystem.js | 7 - .../src/setAppConfig.js | 130 - .../src/setBaseConfig.js | 169 - .../src/setComponentConfig.js | 49 - .../miniapp-compile-config/src/setEntry.js | 33 - packages/miniapp-runtime-config/README.md | 27 - packages/miniapp-runtime-config/package.json | 34 - packages/miniapp-runtime-config/src/index.js | 1 - .../miniapp-runtime-config/src/setConfig.js | 99 - .../platform-loader/src/TraverseImport.js | 12 +- packages/platform-loader/src/index.js | 6 +- .../README.md | 0 .../package.json | 2 +- .../src/index.js | 7 +- .../README.md | 0 .../package.json | 2 +- .../src/build.js | 6 +- .../src/index.js | 0 packages/plugin-rax-app/README.md | 38 + packages/plugin-rax-app/package.json | 45 + packages/plugin-rax-app/src/base.js | 81 + packages/plugin-rax-app/src/config.js | 52 + .../src/constants.js | 2 + packages/plugin-rax-app/src/index.js | 39 + .../src}/postcss.config.js | 27 +- packages/plugin-rax-app/src/setBuild.js | 96 + packages/plugin-rax-app/src/setDev.js | 184 + packages/plugin-rax-app/src/setTest.js | 33 + .../src/userConfig/inlineStyle.js | 106 + packages/plugin-rax-app/src/utils/index.js | 5 + .../src/utils/logWebpackConfig.js | 18 + .../README.md | 0 .../package.json | 2 +- .../src/index.js | 2 +- .../README.md | 0 .../package.json | 2 +- .../src/build.js | 0 .../src/dev.js | 0 .../src/funcBuilder/buildFunctions.js | 5 +- .../src/funcBuilder/constants.js | 0 .../src/funcBuilder/generateFuncPath.js | 0 .../src/funcBuilder/index.js | 0 .../src/generateFunctionConfig.js | 3 +- .../src/generateYaml.js | 0 .../src/index.js | 0 .../README.md | 0 .../package.json | 2 +- .../src/generateYaml.js | 0 .../src/index.js | 10 +- packages/plugin-rax-kraken/package.json | 25 + packages/plugin-rax-kraken/src/constants.js | 3 + packages/plugin-rax-kraken/src/index.js | 60 + packages/plugin-rax-kraken/src/setEntry.js | 23 + packages/plugin-rax-miniapp/package.json | 27 + packages/plugin-rax-miniapp/src/constants.js | 4 + packages/plugin-rax-miniapp/src/index.js | 104 + packages/plugin-rax-miniapp/src/setEntry.js | 24 + .../README.md | 0 .../package.json | 2 +- .../src/index.js | 8 +- .../README.md | 0 .../package.json | 2 +- .../src/__tests__/manifestHelper.js | 64 +- .../src/index.js | 2 +- .../src/manifestHelpers.js | 6 +- .../src/nsr/entryLoader.js | 2 +- .../src/nsr/getBase.js | 4 +- .../src/nsr/getEntryName.js | 0 .../src/plugins/SaveToDesktopPlugin.js | 4 +- .../src/plugins/ServiceWorkerPlugin.js | 3 +- .../src/plugins/SnapshotPlugin.js | 2 +- .../src/setManifestToDocument.js | 11 +- .../src/templates/sw.js | 0 .../src/templates/swbs.js | 0 packages/plugin-rax-web/package.json | 32 + .../src}/DocumentPlugin/index.js | 66 +- .../src}/DocumentPlugin/loader.js | 4 +- packages/plugin-rax-web/src/constants.js | 3 + packages/plugin-rax-web/src/index.js | 82 + .../web => plugin-rax-web/src}/setDev.js | 13 +- packages/plugin-rax-web/src/setEntry.js | 32 + packages/plugin-rax-weex/package.json | 26 + .../src}/WeexFrameworkBannerPlugin.js | 13 +- packages/plugin-rax-weex/src/constants.js | 3 + packages/plugin-rax-weex/src/index.js | 59 + packages/plugin-rax-weex/src/setEntry.js | 28 + packages/postcss-plugin-rpx2vw/package.json | 2 +- .../src/__tests__/index.js | 4 +- packages/postcss-plugin-rpx2vw/src/index.js | 10 +- packages/rax-app-renderer/README.md | 1 + packages/rax-app-renderer/package.json | 35 + packages/rax-app-renderer/src/index.ts | 3 + packages/rax-app-renderer/src/renderer.tsx | 174 + packages/rax-app-renderer/tsconfig.json | 17 + packages/rax-app/CHANGELOG.md | 32 + packages/rax-app/README.md | 1 + packages/rax-app/bin/child-process-start.js | 7 + packages/rax-app/bin/rax-cli.js | 10 + packages/rax-app/package.json | 51 + packages/rax-app/src/index.ts | 46 + packages/rax-app/tsconfig.json | 8 + packages/rax-babel-config/package.json | 2 +- packages/rax-babel-config/src/index.js | 10 +- packages/rax-cli/bin/config.js | 14 +- packages/rax-cli/bin/rax.js | 20 +- .../README.md | 1 - .../package.json | 24 - .../src/BasicEvaluatedExpression.js | 179 - .../src/Dependency.js | 54 - .../src/HotModuleReplacement.runtime.js | 584 - .../src/HotModuleReplacementPlugin.js | 266 - .../src/NullFactory.js | 12 - .../src/ParserHelpers.js | 76 - .../src/RaxJsonpMainTemplate.runtime.js | 82 - .../src/RaxJsonpMainTemplatePlugin.js | 66 - .../src/Template.js | 166 - .../src/UnsupportedFeatureWarning.js | 21 - .../src/WebpackError.js | 11 - .../src/compareLocations.js | 36 - .../src/dependencies/ConstDependency.js | 32 - .../src/dependencies/ModuleDependency.js | 23 - .../ModuleDependencyTemplateAsId.js | 20 - .../dependencies/ModuleHotAcceptDependency.js | 23 - .../ModuleHotDeclineDependency.js | 23 - .../src/dependencies/NullDependency.js | 24 - .../src/dependencies/PrefetchDependency.js | 18 - .../src/globalTemplate.js | 33 - .../src/polyfill/XMLHttpRequest.js | 64 - packages/rax-jest-config/package.json | 2 +- packages/rax-jest-config/src/index.js | 2 +- .../rax-miniapp-babel-plugins/README-zh.md | 22 - packages/rax-miniapp-babel-plugins/README.md | 27 - .../rax-miniapp-babel-plugins/package.json | 26 - .../src/constants.js | 6 - .../rax-miniapp-babel-plugins/src/index.js | 28 - .../plugins/babel-plugin-external-module.js | 19 - .../babel-plugin-handle-native-component.js | 129 - .../babel-plugin-handle-plugin-component.js | 46 - .../plugins/babel-plugin-native-lifecycle.js | 27 - .../plugins/babel-plugin-remove-Function.js | 24 - .../src/utils/CodeError.js | 17 - .../src/utils/extMap.js | 6 - .../src/utils/getFilePath.js | 5 - .../src/utils/getPagePath.js | 13 - .../src/utils/getTagName.js | 5 - .../src/utils/handleComponentAST.js | 89 - .../package.json | 14 - .../src/adaptConfig.js | 98 - .../src/constants.js | 6 - .../src/handleIcon.js | 18 - .../src/index.js | 48 - .../src/safeWriteFile.js | 18 - .../src/transformAppConfig.js | 45 - .../src/transformNativeConfig.js | 16 - .../package.json | 27 - .../src/adapter.js | 34 - .../src/constants.js | 5 - .../src/generators/app.js | 74 - .../src/generators/config.js | 33 - .../src/generators/element.js | 81 - .../src/generators/index.js | 31 - .../src/generators/page.js | 83 - .../src/generators/pkg.js | 18 - .../src/generators/render.js | 21 - .../src/generators/root.js | 33 - .../src/index.js | 210 - .../src/nativeLifeCycle.js | 49 - .../ali-miniapp/custom-component.xml.ejs | 28 - .../src/templates/ali-miniapp/plugin.xml.ejs | 28 - .../src/templates/ali-miniapp/root.xml.ejs | 938 - .../src/templates/ali-miniapp/tool.sjs.ejs | 36 - .../src/templates/app.js.ejs | 6 - .../src/templates/default.css.ejs | 499 - .../src/templates/page.js.ejs | 3 - .../custom-component.xml.ejs | 30 - .../wechat-miniprogram/plugin.xml.ejs | 30 - .../templates/wechat-miniprogram/root.xml.ejs | 964 - .../templates/wechat-miniprogram/tool.wxs.ejs | 35 - .../src/utils/addFileToCompilation.js | 10 - .../src/utils/adjustCSS.js | 97 - .../src/utils/getAssetPath.js | 5 - .../src/utils/getTemplate.js | 16 - .../src/utils/isCSSFile.js | 6 - .../src/utils/minifyCode.js | 46 - .../src/utils/wrapChunks.js | 37 - .../src/webTagList.js | 103 - packages/rax-multi-pages-settings/README.md | 14 - .../rax-multi-pages-settings/package.json | 19 - .../src/MulitPageLoader.js | 77 - .../src/formatPath.js | 5 - .../src/getEntries.js | 29 - .../rax-multi-pages-settings/src/index.js | 10 - .../rax-multi-pages-settings/src/setConfig.js | 51 - .../rax-multi-pages-settings/src/setDevLog.js | 15 - .../src/setDevServer.js | 63 - .../src/template/main.jsx.ejs | 84 - .../rax-quickapp-webpack-plugin/package.json | 19 - .../src/assets/Login/index.ux | 121 - .../src/assets/Login/logo.png | Bin 2316 -> 0 bytes .../src/assets/Login/style.css | 15 - .../src/generateContainer.js | 29 - .../src/generateManifest.js | 43 - .../rax-quickapp-webpack-plugin/src/index.js | 13 - .../src/utils/defaultManifest.json | 35 - .../src/utils/downloadRepo.js | 41 - .../src/utils/file.js | 57 - .../src/utils/spinner.js | 18 - packages/rax-webpack-config/package.json | 3 +- .../src/setWebpackLoaders.js | 4 +- .../src/setWebpackPlugins.js | 10 +- ...ModelPropTypes.js => BoxModelPropTypes.ts} | 4 +- ...PropTypes.js => CSSTransitionPropTypes.ts} | 4 +- .../{ColorPropTypes.js => ColorPropTypes.ts} | 4 +- ...lexboxPropTypes.js => FlexboxPropTypes.ts} | 6 +- .../src/{PropTypes.js => PropTypes.ts} | 11 +- ...tylePropTypes.js => TextStylePropTypes.ts} | 4 +- .../src/{Validation.js => Validation.ts} | 23 +- .../src/__tests__/PropTypes.js | 34 - .../src/__tests__/PropTypes.ts | 32 + ...balCSSVariable.js => globalCSSVariable.ts} | 23 +- .../{normalizeColor.js => normalizeColor.ts} | 5 +- .../{particular.js => particular.ts} | 55 +- ...rsColorScheme.js => prefersColorScheme.ts} | 21 +- .../{transformer.js => transformer.ts} | 24 +- ...{colorProperties.js => colorProperties.ts} | 4 +- ...balCSSVariable.js => globalCSSVariable.ts} | 15 +- .../src/{index.js => index.ts} | 44 +- .../stylesheet-loader/src/normalizeColor.js | 246 - .../stylesheet-loader/src/normalizeColor.ts | 245 + .../src/{particular.js => particular.ts} | 69 +- ...Scheme.js => processPrefersColorScheme.ts} | 5 +- .../{promptMessage.js => promptMessage.ts} | 0 .../src/{transformer.js => transformer.ts} | 22 +- packages/stylesheet-loader/tsconfig.json | 8 + scripts/build.ts | 27 + scripts/check-and-publish.js | 140 - scripts/compile-packages.js | 93 - scripts/dependency-check.ts | 18 + scripts/fn/getPackages.ts | 30 + scripts/fn/shell.ts | 6 + scripts/getPackageInfos.ts | 76 + scripts/owner.ts | 24 + scripts/publish-beta-package.ts | 102 + scripts/publish-package.ts | 38 + scripts/published-info.ts | 11 + scripts/rollback.ts | 21 + scripts/sync.ts | 9 + scripts/tag-version.ts | 32 + scripts/version-check.ts | 36 + scripts/watch.ts | 49 + tsconfig.json | 9 + tsconfig.settings.json | 11 + yarn.lock | 18128 ++++++++++++++++ 565 files changed, 22613 insertions(+), 18746 deletions(-) create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/GIT_COMMIT_SPECIFIC.md create mode 100644 .github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report_cn.md create mode 100644 .github/workflows/beta-publisher.yml create mode 100644 .prettierignore create mode 100644 .prettierrc.js create mode 100644 CHANGELOG.md create mode 100644 README_zh-CN.md delete mode 100644 babel.config.js create mode 100644 codecov.yml delete mode 100644 examples/rax-app-ts/README.md delete mode 100644 examples/rax-app-ts/build.json delete mode 100644 examples/rax-app-ts/src/app.ts delete mode 100644 examples/rax-app-ts/src/components/LogoCss/index.tsx delete mode 100644 examples/rax-app-ts/src/components/LogoCssModule/index.tsx delete mode 100644 examples/rax-app-ts/src/components/LogoLess/index.less delete mode 100644 examples/rax-app-ts/src/components/LogoLess/index.tsx delete mode 100644 examples/rax-app-ts/src/components/LogoLessModule/index.tsx delete mode 100644 examples/rax-app-ts/src/components/LogoSass/index.scss delete mode 100644 examples/rax-app-ts/src/components/LogoSass/index.tsx delete mode 100644 examples/rax-app-ts/src/components/LogoSassModule/index.tsx delete mode 100644 examples/rax-app-ts/src/pages/Home/index.tsx delete mode 100644 examples/rax-app-ts/src/typings.d.ts delete mode 100644 examples/rax-component-js/README.md delete mode 100644 examples/rax-component-js/build.json delete mode 100644 examples/rax-component-js/demo/advance.md delete mode 100644 examples/rax-component-js/demo/basic.md delete mode 100644 examples/rax-component-js/package.json delete mode 100644 examples/rax-component-js/src/index.jsx delete mode 100644 examples/rax-component-ts/README.md delete mode 100644 examples/rax-component-ts/build.json delete mode 100644 examples/rax-component-ts/demo/advance.md delete mode 100644 examples/rax-component-ts/demo/basic.md delete mode 100644 examples/rax-component-ts/package.json delete mode 100644 examples/rax-component-ts/src/index.tsx delete mode 100644 examples/rax-component-ts/tsconfig.json create mode 100644 examples/with-rax-miniapp-compile/README.md create mode 100644 examples/with-rax-miniapp-compile/build.json create mode 100644 examples/with-rax-miniapp-compile/package.json create mode 100644 examples/with-rax-miniapp-compile/src/app.json create mode 100644 examples/with-rax-miniapp-compile/src/app.tsx rename examples/{rax-app-ts/src/components/LogoCssModule/index.module.css => with-rax-miniapp-compile/src/components/Logo/index.css} (63%) create mode 100644 examples/with-rax-miniapp-compile/src/components/Logo/index.tsx create mode 100644 examples/with-rax-miniapp-compile/src/document/index.jsx create mode 100644 examples/with-rax-miniapp-compile/src/miniapp-native/rax.png create mode 100644 examples/with-rax-miniapp-compile/src/pages/About/index.css create mode 100644 examples/with-rax-miniapp-compile/src/pages/About/index.tsx create mode 100644 examples/with-rax-miniapp-compile/src/pages/Home/index.css create mode 100644 examples/with-rax-miniapp-compile/src/pages/Home/index.tsx rename examples/{rax-app-ts => with-rax-miniapp-compile}/tsconfig.json (54%) create mode 100644 examples/with-rax-mpa/README.md create mode 100644 examples/with-rax-mpa/build.json create mode 100644 examples/with-rax-mpa/package.json create mode 100644 examples/with-rax-mpa/public/rax.png create mode 100644 examples/with-rax-mpa/src/app.json create mode 100644 examples/with-rax-mpa/src/app.tsx rename examples/{rax-app-ts/src/components/LogoLessModule/index.module.less => with-rax-mpa/src/components/Logo/index.css} (62%) create mode 100644 examples/with-rax-mpa/src/components/Logo/index.tsx create mode 100644 examples/with-rax-mpa/src/document/index.jsx rename examples/{rax-app-ts/src => with-rax-mpa/src/pages/About}/app.json (71%) create mode 100644 examples/with-rax-mpa/src/pages/About/app.ts create mode 100644 examples/with-rax-mpa/src/pages/About/index.css create mode 100644 examples/with-rax-mpa/src/pages/About/index.tsx create mode 100644 examples/with-rax-mpa/src/pages/Home/index.css create mode 100644 examples/with-rax-mpa/src/pages/Home/index.tsx create mode 100644 examples/with-rax-mpa/tsconfig.json create mode 100644 examples/with-rax-store/README.md create mode 100644 examples/with-rax-store/build.json rename examples/{rax-app-ts => with-rax-store}/package.json (51%) create mode 100644 examples/with-rax-store/src/app.json create mode 100644 examples/with-rax-store/src/app.tsx rename examples/{rax-app-ts/src/components/LogoSassModule/index.module.scss => with-rax-store/src/components/Logo/index.css} (62%) create mode 100644 examples/with-rax-store/src/components/Logo/index.tsx rename examples/{rax-app-ts/src/document/index.jsx => with-rax-store/src/document/index.tsx} (93%) create mode 100644 examples/with-rax-store/src/models/counter.ts create mode 100644 examples/with-rax-store/src/pages/About/index.css create mode 100644 examples/with-rax-store/src/pages/About/index.tsx create mode 100644 examples/with-rax-store/src/pages/Home/index.css create mode 100644 examples/with-rax-store/src/pages/Home/index.tsx create mode 100644 examples/with-rax-store/src/pages/Home/models/counter.ts create mode 100644 examples/with-rax-store/src/pages/Home/store.ts create mode 100644 examples/with-rax-store/src/store.ts create mode 100644 examples/with-rax-store/tsconfig.json create mode 100644 examples/with-rax/README.md create mode 100644 examples/with-rax/build.json create mode 100644 examples/with-rax/package.json create mode 100644 examples/with-rax/public/rax.png create mode 100644 examples/with-rax/src/app.json create mode 100644 examples/with-rax/src/app.tsx create mode 100644 examples/with-rax/src/components/BuggyCounter/index.tsx rename examples/{rax-app-ts/src/components/LogoCss => with-rax/src/components/Logo}/index.css (62%) create mode 100644 examples/with-rax/src/components/Logo/index.tsx create mode 100644 examples/with-rax/src/document/index.jsx create mode 100644 examples/with-rax/src/miniapp-native/rax.png create mode 100644 examples/with-rax/src/pages/About/index.css create mode 100644 examples/with-rax/src/pages/About/index.tsx create mode 100644 examples/with-rax/src/pages/Home/index.css create mode 100644 examples/with-rax/src/pages/Home/index.tsx create mode 100644 examples/with-rax/tsconfig.json rename packages/babel-plugin-transform-jsx-stylesheet/src/__tests__/{index.js => index.ts} (97%) rename packages/babel-plugin-transform-jsx-stylesheet/src/__tests__/{module.js => module.ts} (79%) rename packages/babel-plugin-transform-jsx-stylesheet/src/{constants.js => constants.ts} (100%) rename packages/babel-plugin-transform-jsx-stylesheet/src/{index.js => index.ts} (89%) create mode 100644 packages/babel-plugin-transform-jsx-stylesheet/tsconfig.json delete mode 100644 packages/build-plugin-multi-demo-portal/package.json delete mode 100644 packages/build-plugin-multi-demo-portal/src/build.js delete mode 100644 packages/build-plugin-multi-demo-portal/src/config/demo.html delete mode 100644 packages/build-plugin-multi-demo-portal/src/config/getBaseWebpack.js delete mode 100644 packages/build-plugin-multi-demo-portal/src/config/getDev.js delete mode 100644 packages/build-plugin-multi-demo-portal/src/config/getDistConfig.js delete mode 100644 packages/build-plugin-multi-demo-portal/src/config/portal.html delete mode 100644 packages/build-plugin-multi-demo-portal/src/config/template/portal.hbs delete mode 100644 packages/build-plugin-multi-demo-portal/src/config/utils/generatePortalJs.js delete mode 100644 packages/build-plugin-multi-demo-portal/src/config/utils/getBuildTargets.js delete mode 100644 packages/build-plugin-multi-demo-portal/src/config/utils/getDemos.js delete mode 100644 packages/build-plugin-multi-demo-portal/src/config/utils/parseMarkdown.js delete mode 100644 packages/build-plugin-multi-demo-portal/src/dev.js delete mode 100644 packages/build-plugin-multi-demo-portal/src/index.js delete mode 100644 packages/build-plugin-multi-demo-portal/src/loaders/MarkdownLoader/index.js delete mode 100644 packages/build-plugin-rax-app/package.json delete mode 100644 packages/build-plugin-rax-app/src/build.js delete mode 100644 packages/build-plugin-rax-app/src/config/getWebpackBase.js delete mode 100644 packages/build-plugin-rax-app/src/config/kraken/getBase.js delete mode 100644 packages/build-plugin-rax-app/src/config/kraken/setDev.js delete mode 100644 packages/build-plugin-rax-app/src/config/miniapp/compile/getBase.js delete mode 100644 packages/build-plugin-rax-app/src/config/miniapp/runtime/getBase.js delete mode 100644 packages/build-plugin-rax-app/src/config/processRelativePublicPath.js delete mode 100644 packages/build-plugin-rax-app/src/config/setEntry.js delete mode 100644 packages/build-plugin-rax-app/src/config/user/keys/alias.js delete mode 100644 packages/build-plugin-rax-app/src/config/user/keys/analyzer.js delete mode 100644 packages/build-plugin-rax-app/src/config/user/keys/devPublicPath.js delete mode 100644 packages/build-plugin-rax-app/src/config/user/keys/devServer.js delete mode 100644 packages/build-plugin-rax-app/src/config/user/keys/hash.js delete mode 100644 packages/build-plugin-rax-app/src/config/user/keys/inlineStyle.js delete mode 100644 packages/build-plugin-rax-app/src/config/user/keys/outputDir.js delete mode 100644 packages/build-plugin-rax-app/src/config/user/keys/publicPath.js delete mode 100644 packages/build-plugin-rax-app/src/config/user/keys/sourceMap.js delete mode 100644 packages/build-plugin-rax-app/src/config/user/keys/stats.js delete mode 100644 packages/build-plugin-rax-app/src/config/user/setConfig.js delete mode 100644 packages/build-plugin-rax-app/src/config/web/getBase.js delete mode 100644 packages/build-plugin-rax-app/src/config/weex/getBase.js delete mode 100644 packages/build-plugin-rax-app/src/config/weex/setDev.js delete mode 100644 packages/build-plugin-rax-app/src/dev.js delete mode 100644 packages/build-plugin-rax-app/src/index.js delete mode 100644 packages/build-plugin-rax-app/src/loaders/AppConfigLoader/getDepPath.js delete mode 100644 packages/build-plugin-rax-app/src/loaders/AppConfigLoader/index.js delete mode 100644 packages/build-plugin-rax-app/src/plugins/DocumentPlugin/config.js delete mode 100644 packages/build-plugin-rax-block/README.md delete mode 100644 packages/build-plugin-rax-block/package.json delete mode 100644 packages/build-plugin-rax-block/src/index.js delete mode 100644 packages/build-plugin-rax-component/README.md delete mode 100644 packages/build-plugin-rax-component/package.json delete mode 100644 packages/build-plugin-rax-component/src/build.js delete mode 100644 packages/build-plugin-rax-component/src/config/demo.html delete mode 100644 packages/build-plugin-rax-component/src/config/getBaseWebpack.js delete mode 100644 packages/build-plugin-rax-component/src/config/getDemos.js delete mode 100644 packages/build-plugin-rax-component/src/config/getDistConfig.js delete mode 100644 packages/build-plugin-rax-component/src/config/getES6Config.js delete mode 100644 packages/build-plugin-rax-component/src/config/getUMDConfig.js delete mode 100644 packages/build-plugin-rax-component/src/config/miniapp/getBase.js delete mode 100644 packages/build-plugin-rax-component/src/config/miniapp/getOutputPath.js delete mode 100644 packages/build-plugin-rax-component/src/config/node/getDev.js delete mode 100644 packages/build-plugin-rax-component/src/config/node/ignoreLoader.js delete mode 100644 packages/build-plugin-rax-component/src/config/parseMarkdown.js delete mode 100644 packages/build-plugin-rax-component/src/config/user/default.config.js delete mode 100644 packages/build-plugin-rax-component/src/config/user/keys/devPublicPath.js delete mode 100644 packages/build-plugin-rax-component/src/config/user/keys/devServer.js delete mode 100644 packages/build-plugin-rax-component/src/config/user/keys/mockNodeEnv.js delete mode 100644 packages/build-plugin-rax-component/src/config/user/keys/outputDir.js delete mode 100644 packages/build-plugin-rax-component/src/config/user/keys/publicPath.js delete mode 100644 packages/build-plugin-rax-component/src/config/user/setConfig.js delete mode 100644 packages/build-plugin-rax-component/src/config/web/getDev.js delete mode 100644 packages/build-plugin-rax-component/src/config/weex/getDev.js delete mode 100644 packages/build-plugin-rax-component/src/constants.js delete mode 100644 packages/build-plugin-rax-component/src/dev.js delete mode 100644 packages/build-plugin-rax-component/src/gulp/compile.js delete mode 100644 packages/build-plugin-rax-component/src/gulp/filePatterns.js delete mode 100644 packages/build-plugin-rax-component/src/gulp/gulpfile.js delete mode 100644 packages/build-plugin-rax-component/src/gulp/params.js delete mode 100644 packages/build-plugin-rax-component/src/index.js delete mode 100644 packages/build-plugin-rax-component/src/loaders/MarkdownLoader/index.js delete mode 100644 packages/build-plugin-rax-component/src/plugins/WeexFrameworkBannerPlugin.js delete mode 100644 packages/build-plugin-rax-component/src/watchLib.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/README.md delete mode 100644 packages/build-plugin-rax-miniapp-plugin/package.json delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/build.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/config/getBase.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/config/getOutputPath.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/config/getPluginConfig.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/config/platformConfig.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/config/setEntry.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/config/targetPlatformMap.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/config/user/keys/alias.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/config/user/keys/devServer.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/config/user/keys/outputDir.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/config/user/setConfig.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/constants.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/dev.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/index.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/CopyJsx2mpRuntime.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/CopyPublicFile.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/GenerateAppCss.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/ModifyOutputFileSystem.js delete mode 100644 packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/ProcessPluginJson.js delete mode 100644 packages/build-plugin-rax-multi-pages/README.md delete mode 100644 packages/build-plugin-rax-multi-pages/package.json delete mode 100644 packages/build-plugin-rax-multi-pages/src/index.js delete mode 100644 packages/build-plugin-rax-ssr/README.md delete mode 100644 packages/build-plugin-rax-ssr/package.json delete mode 100644 packages/build-plugin-rax-ssr/src/index.js delete mode 100644 packages/build-plugin-rax-ssr/src/ssr/entryLoader.js delete mode 100644 packages/build-plugin-rax-ssr/src/ssr/entryPlugin.js delete mode 100644 packages/build-plugin-rax-ssr/src/ssr/getBase.js delete mode 100644 packages/build-plugin-rax-ssr/src/ssr/getEntryName.js delete mode 100644 packages/build-plugin-rax-ssr/src/ssr/setBuild.js delete mode 100644 packages/build-plugin-rax-ssr/src/ssr/setDev.js delete mode 100644 packages/build-plugin-rax-ssr/src/web/setDev.js delete mode 100644 packages/build-plugin-rax-theme/README.md delete mode 100644 packages/build-plugin-rax-theme/package.json delete mode 100644 packages/build-plugin-rax-theme/src/index.js delete mode 100644 packages/eslint-config-rax/README.md delete mode 100644 packages/eslint-config-rax/index.js delete mode 100644 packages/eslint-config-rax/package.json delete mode 100644 packages/eslint-config-rax/rules/base.js delete mode 100644 packages/eslint-config-rax/rules/globals.js delete mode 100644 packages/eslint-config-rax/rules/react.js delete mode 100644 packages/eslint-config-rax/rules/typescript.js delete mode 100644 packages/eslint-plugin-module/README.md delete mode 100644 packages/eslint-plugin-module/package.json delete mode 100644 packages/eslint-plugin-module/src/index.js delete mode 100644 packages/eslint-plugin-module/src/rules/no-implicit-dependencies.js delete mode 100644 packages/image-source-loader/README.md delete mode 100644 packages/image-source-loader/mimes.json delete mode 100644 packages/image-source-loader/package.json delete mode 100644 packages/image-source-loader/src/__mocks__/one-pixel-png.js delete mode 100644 packages/image-source-loader/src/__tests__/index.js delete mode 100644 packages/image-source-loader/src/index.js delete mode 100644 packages/jsx2mp-cli/.gitignore delete mode 100644 packages/jsx2mp-cli/.npmignore delete mode 100644 packages/jsx2mp-cli/README.md delete mode 100644 packages/jsx2mp-cli/__tests__/component.js delete mode 100644 packages/jsx2mp-cli/bin/jsx2mp-build.js delete mode 100644 packages/jsx2mp-cli/bin/jsx2mp-start.js delete mode 100755 packages/jsx2mp-cli/bin/jsx2mp.js delete mode 100644 packages/jsx2mp-cli/checkPkgVersion.js delete mode 100644 packages/jsx2mp-cli/default.js delete mode 100644 packages/jsx2mp-cli/demo/assets/rax.png delete mode 100644 packages/jsx2mp-cli/demo/component.js delete mode 100644 packages/jsx2mp-cli/demo/package.json delete mode 100644 packages/jsx2mp-cli/getWebpackConfig.js delete mode 100644 packages/jsx2mp-cli/index.js delete mode 100644 packages/jsx2mp-cli/package.json delete mode 100644 packages/jsx2mp-cli/plugins/runtime.js delete mode 100644 packages/jsx2mp-cli/utils/file.js delete mode 100644 packages/jsx2mp-cli/utils/log.js delete mode 100644 packages/jsx2mp-cli/utils/moduleResolve.js delete mode 100644 packages/jsx2mp-cli/utils/platformConfig.js delete mode 100644 packages/jsx2mp-cli/utils/removeExt.js delete mode 100644 packages/jsx2mp-cli/utils/spinner.js delete mode 100644 packages/jsx2mp-loader/package.json delete mode 100644 packages/jsx2mp-loader/src/app-loader.js delete mode 100644 packages/jsx2mp-loader/src/babel-plugin-rename-import.js delete mode 100644 packages/jsx2mp-loader/src/cached.js delete mode 100644 packages/jsx2mp-loader/src/component-loader.js delete mode 100644 packages/jsx2mp-loader/src/constants.js delete mode 100644 packages/jsx2mp-loader/src/defaultStyle.js delete mode 100644 packages/jsx2mp-loader/src/file-loader.js delete mode 100644 packages/jsx2mp-loader/src/output.js delete mode 100644 packages/jsx2mp-loader/src/page-loader.js delete mode 100644 packages/jsx2mp-loader/src/script-loader.js delete mode 100644 packages/jsx2mp-loader/src/styleProcessor.js delete mode 100644 packages/jsx2mp-loader/src/utils/addSourceMap.js delete mode 100644 packages/jsx2mp-loader/src/utils/dce.js delete mode 100644 packages/jsx2mp-loader/src/utils/getAliasCorrespondingValue.js delete mode 100644 packages/jsx2mp-loader/src/utils/isMiniappComponent.js delete mode 100644 packages/jsx2mp-loader/src/utils/judgeModule.js delete mode 100644 packages/jsx2mp-loader/src/utils/minifyCode.js delete mode 100644 packages/jsx2mp-loader/src/utils/parseRequest.js delete mode 100644 packages/jsx2mp-loader/src/utils/pathHelper.js delete mode 100644 packages/miniapp-builder-shared/README.md delete mode 100644 packages/miniapp-builder-shared/package.json delete mode 100644 packages/miniapp-builder-shared/src/filterNativePages.js delete mode 100644 packages/miniapp-builder-shared/src/getAppConfig.js delete mode 100644 packages/miniapp-builder-shared/src/getOutputPath.js delete mode 100644 packages/miniapp-builder-shared/src/index.js delete mode 100644 packages/miniapp-builder-shared/src/pathHelper.js delete mode 100644 packages/miniapp-builder-shared/src/platformMap.js delete mode 100644 packages/miniapp-builder-shared/src/utils/constants.js delete mode 100644 packages/miniapp-builder-shared/src/utils/getRouteName.js delete mode 100644 packages/miniapp-compile-config/README.md delete mode 100644 packages/miniapp-compile-config/package.json delete mode 100644 packages/miniapp-compile-config/src/index.js delete mode 100644 packages/miniapp-compile-config/src/plugins/CopyJsx2mpRuntime.js delete mode 100644 packages/miniapp-compile-config/src/plugins/CopyPublicFile.js delete mode 100644 packages/miniapp-compile-config/src/plugins/ModifyOutputFileSystem.js delete mode 100644 packages/miniapp-compile-config/src/setAppConfig.js delete mode 100644 packages/miniapp-compile-config/src/setBaseConfig.js delete mode 100644 packages/miniapp-compile-config/src/setComponentConfig.js delete mode 100644 packages/miniapp-compile-config/src/setEntry.js delete mode 100644 packages/miniapp-runtime-config/README.md delete mode 100644 packages/miniapp-runtime-config/package.json delete mode 100644 packages/miniapp-runtime-config/src/index.js delete mode 100644 packages/miniapp-runtime-config/src/setConfig.js rename packages/{build-plugin-midway-faas => plugin-midway-faas}/README.md (100%) rename packages/{build-plugin-midway-faas => plugin-midway-faas}/package.json (94%) rename packages/{build-plugin-midway-faas => plugin-midway-faas}/src/index.js (87%) rename packages/{build-plugin-rax-api-builder => plugin-rax-api-builder}/README.md (100%) rename packages/{build-plugin-rax-api-builder => plugin-rax-api-builder}/package.json (97%) rename packages/{build-plugin-rax-api-builder => plugin-rax-api-builder}/src/build.js (95%) rename packages/{build-plugin-rax-api-builder => plugin-rax-api-builder}/src/index.js (100%) create mode 100644 packages/plugin-rax-app/README.md create mode 100644 packages/plugin-rax-app/package.json create mode 100644 packages/plugin-rax-app/src/base.js create mode 100644 packages/plugin-rax-app/src/config.js rename packages/{build-plugin-rax-app => plugin-rax-app}/src/constants.js (76%) create mode 100644 packages/plugin-rax-app/src/index.js rename packages/{build-plugin-rax-app/src/config => plugin-rax-app/src}/postcss.config.js (61%) create mode 100644 packages/plugin-rax-app/src/setBuild.js create mode 100644 packages/plugin-rax-app/src/setDev.js create mode 100644 packages/plugin-rax-app/src/setTest.js create mode 100644 packages/plugin-rax-app/src/userConfig/inlineStyle.js create mode 100644 packages/plugin-rax-app/src/utils/index.js create mode 100644 packages/plugin-rax-app/src/utils/logWebpackConfig.js rename packages/{build-plugin-rax-compat-react => plugin-rax-compat-react}/README.md (100%) rename packages/{build-plugin-rax-compat-react => plugin-rax-compat-react}/package.json (86%) rename packages/{build-plugin-rax-compat-react => plugin-rax-compat-react}/src/index.js (89%) rename packages/{build-plugin-rax-faas => plugin-rax-faas}/README.md (100%) rename packages/{build-plugin-rax-faas => plugin-rax-faas}/package.json (92%) rename packages/{build-plugin-rax-faas => plugin-rax-faas}/src/build.js (100%) rename packages/{build-plugin-rax-faas => plugin-rax-faas}/src/dev.js (100%) rename packages/{build-plugin-rax-faas => plugin-rax-faas}/src/funcBuilder/buildFunctions.js (84%) rename packages/{build-plugin-rax-faas => plugin-rax-faas}/src/funcBuilder/constants.js (100%) rename packages/{build-plugin-rax-faas => plugin-rax-faas}/src/funcBuilder/generateFuncPath.js (100%) rename packages/{build-plugin-rax-faas => plugin-rax-faas}/src/funcBuilder/index.js (100%) rename packages/{build-plugin-rax-faas => plugin-rax-faas}/src/generateFunctionConfig.js (90%) rename packages/{build-plugin-rax-faas => plugin-rax-faas}/src/generateYaml.js (100%) rename packages/{build-plugin-rax-faas => plugin-rax-faas}/src/index.js (100%) rename packages/{build-plugin-rax-fc => plugin-rax-fc}/README.md (100%) rename packages/{build-plugin-rax-fc => plugin-rax-fc}/package.json (91%) rename packages/{build-plugin-rax-fc => plugin-rax-fc}/src/generateYaml.js (100%) rename packages/{build-plugin-rax-fc => plugin-rax-fc}/src/index.js (91%) create mode 100644 packages/plugin-rax-kraken/package.json create mode 100644 packages/plugin-rax-kraken/src/constants.js create mode 100644 packages/plugin-rax-kraken/src/index.js create mode 100644 packages/plugin-rax-kraken/src/setEntry.js create mode 100644 packages/plugin-rax-miniapp/package.json create mode 100644 packages/plugin-rax-miniapp/src/constants.js create mode 100644 packages/plugin-rax-miniapp/src/index.js create mode 100644 packages/plugin-rax-miniapp/src/setEntry.js rename packages/{build-plugin-rax-now => plugin-rax-now}/README.md (100%) rename packages/{build-plugin-rax-now => plugin-rax-now}/package.json (86%) rename packages/{build-plugin-rax-now => plugin-rax-now}/src/index.js (90%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/README.md (100%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/package.json (94%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/src/__tests__/manifestHelper.js (82%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/src/index.js (98%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/src/manifestHelpers.js (97%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/src/nsr/entryLoader.js (98%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/src/nsr/getBase.js (97%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/src/nsr/getEntryName.js (100%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/src/plugins/SaveToDesktopPlugin.js (99%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/src/plugins/ServiceWorkerPlugin.js (96%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/src/plugins/SnapshotPlugin.js (99%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/src/setManifestToDocument.js (88%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/src/templates/sw.js (100%) rename packages/{build-plugin-rax-pha => plugin-rax-pha}/src/templates/swbs.js (100%) create mode 100644 packages/plugin-rax-web/package.json rename packages/{build-plugin-rax-app/src/plugins => plugin-rax-web/src}/DocumentPlugin/index.js (79%) rename packages/{build-plugin-rax-app/src/plugins => plugin-rax-web/src}/DocumentPlugin/loader.js (98%) create mode 100644 packages/plugin-rax-web/src/constants.js create mode 100644 packages/plugin-rax-web/src/index.js rename packages/{build-plugin-rax-app/src/config/web => plugin-rax-web/src}/setDev.js (71%) create mode 100644 packages/plugin-rax-web/src/setEntry.js create mode 100644 packages/plugin-rax-weex/package.json rename packages/{build-plugin-rax-app/src/plugins => plugin-rax-weex/src}/WeexFrameworkBannerPlugin.js (85%) create mode 100644 packages/plugin-rax-weex/src/constants.js create mode 100644 packages/plugin-rax-weex/src/index.js create mode 100644 packages/plugin-rax-weex/src/setEntry.js create mode 100644 packages/rax-app-renderer/README.md create mode 100644 packages/rax-app-renderer/package.json create mode 100644 packages/rax-app-renderer/src/index.ts create mode 100644 packages/rax-app-renderer/src/renderer.tsx create mode 100644 packages/rax-app-renderer/tsconfig.json create mode 100644 packages/rax-app/CHANGELOG.md create mode 100644 packages/rax-app/README.md create mode 100644 packages/rax-app/bin/child-process-start.js create mode 100755 packages/rax-app/bin/rax-cli.js create mode 100644 packages/rax-app/package.json create mode 100644 packages/rax-app/src/index.ts create mode 100644 packages/rax-app/tsconfig.json delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/README.md delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/package.json delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/BasicEvaluatedExpression.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/Dependency.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/HotModuleReplacement.runtime.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/HotModuleReplacementPlugin.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/NullFactory.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/ParserHelpers.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/RaxJsonpMainTemplate.runtime.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/RaxJsonpMainTemplatePlugin.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/Template.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/UnsupportedFeatureWarning.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/WebpackError.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/compareLocations.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ConstDependency.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleDependency.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleDependencyTemplateAsId.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleHotAcceptDependency.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleHotDeclineDependency.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/NullDependency.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/PrefetchDependency.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/globalTemplate.js delete mode 100644 packages/rax-hot-module-replacement-webpack-plugin/src/polyfill/XMLHttpRequest.js delete mode 100644 packages/rax-miniapp-babel-plugins/README-zh.md delete mode 100644 packages/rax-miniapp-babel-plugins/README.md delete mode 100644 packages/rax-miniapp-babel-plugins/package.json delete mode 100644 packages/rax-miniapp-babel-plugins/src/constants.js delete mode 100644 packages/rax-miniapp-babel-plugins/src/index.js delete mode 100644 packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-external-module.js delete mode 100644 packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-handle-native-component.js delete mode 100644 packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-handle-plugin-component.js delete mode 100644 packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-native-lifecycle.js delete mode 100644 packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-remove-Function.js delete mode 100644 packages/rax-miniapp-babel-plugins/src/utils/CodeError.js delete mode 100644 packages/rax-miniapp-babel-plugins/src/utils/extMap.js delete mode 100644 packages/rax-miniapp-babel-plugins/src/utils/getFilePath.js delete mode 100644 packages/rax-miniapp-babel-plugins/src/utils/getPagePath.js delete mode 100644 packages/rax-miniapp-babel-plugins/src/utils/getTagName.js delete mode 100644 packages/rax-miniapp-babel-plugins/src/utils/handleComponentAST.js delete mode 100644 packages/rax-miniapp-config-webpack-plugin/package.json delete mode 100644 packages/rax-miniapp-config-webpack-plugin/src/adaptConfig.js delete mode 100644 packages/rax-miniapp-config-webpack-plugin/src/constants.js delete mode 100644 packages/rax-miniapp-config-webpack-plugin/src/handleIcon.js delete mode 100644 packages/rax-miniapp-config-webpack-plugin/src/index.js delete mode 100644 packages/rax-miniapp-config-webpack-plugin/src/safeWriteFile.js delete mode 100644 packages/rax-miniapp-config-webpack-plugin/src/transformAppConfig.js delete mode 100644 packages/rax-miniapp-config-webpack-plugin/src/transformNativeConfig.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/package.json delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/adapter.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/constants.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/generators/app.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/generators/config.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/generators/element.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/generators/index.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/generators/page.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/generators/pkg.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/generators/render.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/generators/root.js delete mode 100755 packages/rax-miniapp-runtime-webpack-plugin/src/index.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/nativeLifeCycle.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/templates/ali-miniapp/custom-component.xml.ejs delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/templates/ali-miniapp/plugin.xml.ejs delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/templates/ali-miniapp/root.xml.ejs delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/templates/ali-miniapp/tool.sjs.ejs delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/templates/app.js.ejs delete mode 100755 packages/rax-miniapp-runtime-webpack-plugin/src/templates/default.css.ejs delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/templates/page.js.ejs delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/templates/wechat-miniprogram/custom-component.xml.ejs delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/templates/wechat-miniprogram/plugin.xml.ejs delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/templates/wechat-miniprogram/root.xml.ejs delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/templates/wechat-miniprogram/tool.wxs.ejs delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/utils/addFileToCompilation.js delete mode 100755 packages/rax-miniapp-runtime-webpack-plugin/src/utils/adjustCSS.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/utils/getAssetPath.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/utils/getTemplate.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/utils/isCSSFile.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/utils/minifyCode.js delete mode 100644 packages/rax-miniapp-runtime-webpack-plugin/src/utils/wrapChunks.js delete mode 100755 packages/rax-miniapp-runtime-webpack-plugin/src/webTagList.js delete mode 100644 packages/rax-multi-pages-settings/README.md delete mode 100644 packages/rax-multi-pages-settings/package.json delete mode 100644 packages/rax-multi-pages-settings/src/MulitPageLoader.js delete mode 100644 packages/rax-multi-pages-settings/src/formatPath.js delete mode 100644 packages/rax-multi-pages-settings/src/getEntries.js delete mode 100644 packages/rax-multi-pages-settings/src/index.js delete mode 100644 packages/rax-multi-pages-settings/src/setConfig.js delete mode 100644 packages/rax-multi-pages-settings/src/setDevLog.js delete mode 100644 packages/rax-multi-pages-settings/src/setDevServer.js delete mode 100644 packages/rax-multi-pages-settings/src/template/main.jsx.ejs delete mode 100644 packages/rax-quickapp-webpack-plugin/package.json delete mode 100644 packages/rax-quickapp-webpack-plugin/src/assets/Login/index.ux delete mode 100644 packages/rax-quickapp-webpack-plugin/src/assets/Login/logo.png delete mode 100644 packages/rax-quickapp-webpack-plugin/src/assets/Login/style.css delete mode 100644 packages/rax-quickapp-webpack-plugin/src/generateContainer.js delete mode 100644 packages/rax-quickapp-webpack-plugin/src/generateManifest.js delete mode 100644 packages/rax-quickapp-webpack-plugin/src/index.js delete mode 100644 packages/rax-quickapp-webpack-plugin/src/utils/defaultManifest.json delete mode 100644 packages/rax-quickapp-webpack-plugin/src/utils/downloadRepo.js delete mode 100644 packages/rax-quickapp-webpack-plugin/src/utils/file.js delete mode 100644 packages/rax-quickapp-webpack-plugin/src/utils/spinner.js rename packages/stylesheet-loader/src/{BoxModelPropTypes.js => BoxModelPropTypes.ts} (97%) rename packages/stylesheet-loader/src/{CSSTransitionPropTypes.js => CSSTransitionPropTypes.ts} (84%) rename packages/stylesheet-loader/src/{ColorPropTypes.js => ColorPropTypes.ts} (89%) rename packages/stylesheet-loader/src/{FlexboxPropTypes.js => FlexboxPropTypes.ts} (91%) rename packages/stylesheet-loader/src/{PropTypes.js => PropTypes.ts} (83%) rename packages/stylesheet-loader/src/{TextStylePropTypes.js => TextStylePropTypes.ts} (93%) rename packages/stylesheet-loader/src/{Validation.js => Validation.ts} (69%) delete mode 100644 packages/stylesheet-loader/src/__tests__/PropTypes.js create mode 100644 packages/stylesheet-loader/src/__tests__/PropTypes.ts rename packages/stylesheet-loader/src/__tests__/{globalCSSVariable.js => globalCSSVariable.ts} (90%) rename packages/stylesheet-loader/src/__tests__/{normalizeColor.js => normalizeColor.ts} (95%) rename packages/stylesheet-loader/src/__tests__/{particular.js => particular.ts} (73%) rename packages/stylesheet-loader/src/__tests__/{prefersColorScheme.js => prefersColorScheme.ts} (74%) rename packages/stylesheet-loader/src/__tests__/{transformer.js => transformer.ts} (91%) rename packages/stylesheet-loader/src/{colorProperties.js => colorProperties.ts} (74%) rename packages/stylesheet-loader/src/{globalCSSVariable.js => globalCSSVariable.ts} (75%) rename packages/stylesheet-loader/src/{index.js => index.ts} (87%) delete mode 100644 packages/stylesheet-loader/src/normalizeColor.js create mode 100644 packages/stylesheet-loader/src/normalizeColor.ts rename packages/stylesheet-loader/src/{particular.js => particular.ts} (72%) rename packages/stylesheet-loader/src/{processPrefersColorScheme.js => processPrefersColorScheme.ts} (91%) rename packages/stylesheet-loader/src/{promptMessage.js => promptMessage.ts} (100%) rename packages/stylesheet-loader/src/{transformer.js => transformer.ts} (87%) create mode 100644 packages/stylesheet-loader/tsconfig.json create mode 100644 scripts/build.ts delete mode 100644 scripts/check-and-publish.js delete mode 100644 scripts/compile-packages.js create mode 100644 scripts/dependency-check.ts create mode 100644 scripts/fn/getPackages.ts create mode 100644 scripts/fn/shell.ts create mode 100644 scripts/getPackageInfos.ts create mode 100644 scripts/owner.ts create mode 100644 scripts/publish-beta-package.ts create mode 100644 scripts/publish-package.ts create mode 100644 scripts/published-info.ts create mode 100644 scripts/rollback.ts create mode 100644 scripts/sync.ts create mode 100644 scripts/tag-version.ts create mode 100644 scripts/version-check.ts create mode 100644 scripts/watch.ts create mode 100644 tsconfig.json create mode 100644 tsconfig.settings.json create mode 100644 yarn.lock diff --git a/.eslintignore b/.eslintignore index b4053cd18..6fd0e00e6 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,11 +1,26 @@ -node_modules -lib -dist -build -coverage -expected -website -gh-pages -vendors -eslint-config-rax -examples \ No newline at end of file +# 忽略目录 +examples/ +scripts/ +build/ +test/ +tests/ +node_modules/ +dist/ +out/ + +# node 覆盖率文件 +coverage/ + +# 忽略测试文件 +__tests__/ +/packages/*/lib/ + +# 忽略第三方包 +/vendor/loader.js + +# 忽略文件 +**/*-min.js +**/*.min.js + +workspace/ +__mocks__/ diff --git a/.eslintrc.js b/.eslintrc.js index d6e2ba389..e6872a32f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,3 +1,14 @@ -module.exports = { - extends: ['rax'] -}; +const { getESLintConfig } = require('@iceworks/spec'); + +// https://www.npmjs.com/package/@iceworks/spec +module.exports = getESLintConfig('rax-ts', { + rules: { + 'no-useless-escape': 'off', + 'no-console': 'off', + '@typescript-eslint/no-require-imports': 'off', + '@iceworks/best-practices/no-js-in-ts-project': 'off', + 'no-param-reassign': 'off', + 'max-len': 'off', + '@typescript-eslint/restrict-plus-operands': 'off' + } +}); diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 000000000..13b0a2e92 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,93 @@ +# Contributing Guide + +Hi! I’m really excited that you are interested in contributing to Rax. Before submitting your contribution though, please make sure to take a moment and read through the following guidelines. + +- [Setup Environment](#setup-environment) +- [Run Examples](#run-examples) +- [Publish Packages](publish-packages) +- [Pull Request Guidelines](#pull-request-guidelines) +- [Issue Reporting Guidelines](#issue-reporting-guidelines) +- [Git Commit Specific](#git-commit-specific) + +## Setup Environment + +clone repo and initialize the setup environment: + +```bash +# 1. clone and setup +$ git clone git@github.com:raxjs/rax-app.git +$ cd rax-app && npm run setup + +# 2. watch packages +$ npm run watch +``` + +## Run Examples + +We provide a lot of examples, you can run the examples: + +```bash +$ cd examples/basic-spa +$ npm link ../../packages/rax-app +$ npm start +``` + +## Publish Packages + +When you need to release, you can execute the command: + +```bash +$ npm run publish +# 1. ✔️ ✔️ ✔️ Checking the working tree status... +# 2. 📦 📦 📦 Building packages... +# 3. ⚡ ⚡ ⚡ Update package version automatically... +# 4. 🚀 🚀 🚀 Start publishing... +# 5. 🔖 🔖 🔖 Commit & Create tag'... +# 6. 💡 💡 💡 Start syncing... +``` + +* When you need to release a latest version, the tag will be created automatically, running `npm publish` will tag your package with the `latest` dist-tag. +* To publish a package with the `beta` dist-tag, you can choose to release rc、beta、alpha versions, the tag will not be created. + +## Rollback Packages + +When a serious bug occurs in the production environment, you can backtrack the package version: + +```bash +# rollback packages +$ npm run rollback + +# sync packages +$ npm run sync +``` + + +## Pull Request Guidelines + +- Only code that's ready for release should be committed to the master branch. All development should be done in dedicated branches. +- Checkout a **new** topic branch from master branch, and merge back against master branch. +- Make sure `npm test` passes. +- If adding new feature: + - Add accompanying test case. + - Provide convincing reason to add this feature. Ideally you should open a suggestion issue first and have it greenlighted before working on it. +- If fixing a bug: + - If you are resolving a special issue, add `(fix #xxxx[,#xxx])` (#xxxx is the issue id) in your PR title for a better release log, e.g. `update entities encoding/decoding (fix #3899)`. + - Provide detailed description of the bug in the PR. Live demo preferred. + - Add appropriate test coverage if applicable. + +## Issue Reporting Guidelines + +- The issue list of this repo is **exclusively** for bug reports and feature requests. Non-conforming issues will be closed immediately. + - For simple beginner questions, you can get quick answers from + - For more complicated questions, you can use Google or StackOverflow. Make sure to provide enough information when asking your questions - this makes it easier for others to help you! +- Try to search for your issue, it may have already been answered or even fixed in the development branch. +- It is **required** that you clearly describe the steps necessary to reproduce the issue you are running into. Issues with no clear repro steps will not be triaged. If an issue labeled "need repro" receives no further input from the issue author for more than 5 days, it will be closed. +- For bugs that involves build setups, you can create a reproduction repository with steps in the README. +- If your issue is resolved but still open, don’t hesitate to close it. In case you found a solution by yourself, it could be helpful to explain how you fixed it. + +## Git Commit Specific + +- Your commits message must follow our [git commit specific](./GIT_COMMIT_SPECIFIC.md). +- We will check your commit message, if it does not conform to the specification, the commit will be automatically refused, make sure you have read the specification above. +- You could use `git cz` with a CLI interface to replace `git commit` command, it will help you to build a proper commit-message, see [commitizen](https://github.com/commitizen/cz-cli). +- It's OK to have multiple small commits as you work on your branch - we will let GitHub automatically squash it before merging. diff --git a/.github/GIT_COMMIT_SPECIFIC.md b/.github/GIT_COMMIT_SPECIFIC.md new file mode 100644 index 000000000..b5b6d10e8 --- /dev/null +++ b/.github/GIT_COMMIT_SPECIFIC.md @@ -0,0 +1,39 @@ +# GIT COMMIT MESSAGE CHEAT SHEET + +**Proposed format of the commit message** + +``` +: + + +``` + +All lines are wrapped at 100 characters ! + +**Allowed ``** + +- feat (A new feature) +- fix (A bug fix) +- docs (Documentation only changes) +- style (Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)) +- perf (A code change that improves performance) +- refactor (A code change that neither fixes a bug nor adds a feature) +- test (Adding missing tests or correcting existing tests) +- build (Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)) +- ci (Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)) +- chore (Other changes that don't modify src or test files) +- revert (Reverts a previous commit) +- release (Relase version) + + +**Breaking changes** + +All breaking changes have to be mentioned in message body, on separated line: + +​ _Breaks removed $browser.setUrl() method (use $browser.url(newUrl))_ +​ _Breaks ng: repeat option is no longer supported on selects (use ng:options)_ + +**Message body** + +- uses the imperative, present tense: “change” not “changed” nor “changes” +- includes motivation for the change and contrasts with previous behavior diff --git a/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md new file mode 100644 index 000000000..9d2b36a25 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md @@ -0,0 +1,22 @@ +--- +name: 'Bug report' +about: 'Report rax-app, components, documents and other issues' +title: '' +labels: '' +assignees: '' +--- + +## What is the current behavior? + + + +## What is the expected behavior?** + +## Any additional comments? + +- **rax-app Version**: +- **build.json Configuration**: +- **Node Version**: +- **Platform**: diff --git a/.github/ISSUE_TEMPLATE/bug_report_cn.md b/.github/ISSUE_TEMPLATE/bug_report_cn.md new file mode 100644 index 000000000..40e770a19 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report_cn.md @@ -0,0 +1,38 @@ +--- +name: '反馈缺陷问题' +about: '反馈框架 rax-app、文档等缺陷问题' +title: '' +labels: '' +assignees: '' +--- + + + + + +## 发生了什么? + + + +## 复现步骤,错误日志以及相关配置 + +> 建议并上传到你的 GitHub 仓库,请使用 `yarn init rax ` 选择 Lite 模板,这样您的问题我们会更高优先级的进行解决。 + + + + + +## 期望的结果是什么 + + + +## 相关环境信息 + +- **rax-app 版本**: +- **build.json 配置**: +- **Node 版本**: +- **操作系统**: diff --git a/.github/workflows/auto-publisher.yml b/.github/workflows/auto-publisher.yml index 89bc4d1f5..83346780c 100644 --- a/.github/workflows/auto-publisher.yml +++ b/.github/workflows/auto-publisher.yml @@ -4,7 +4,6 @@ on: push: branches: - master - - 'releases/**' jobs: build-and-publish: @@ -15,9 +14,10 @@ jobs: with: node-version: 10 registry-url: https://registry.npmjs.org/ - - run: npm i - run: npm run setup - - run: npm run build - - run: npm run check-and-publish + - run: npm run publish env: - NODE_AUTH_TOKEN: ${{secrets.npm_token}} + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }} + ACCESS_KEY_SECRET: ${{ secrets.ACCESS_KEY_SECRET }} + REGISTRY: https://registry.npmjs.org diff --git a/.github/workflows/beta-publisher.yml b/.github/workflows/beta-publisher.yml new file mode 100644 index 000000000..fe1dbd1a5 --- /dev/null +++ b/.github/workflows/beta-publisher.yml @@ -0,0 +1,24 @@ +name: Beta Publisher + +on: + push: + branches: + - beta + +jobs: + build-and-publish-beta: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: nelonoel/branch-name@v1 + - uses: actions/setup-node@v1 + with: + node-version: 10 + registry-url: https://registry.npmjs.org/ + - run: npm run setup + - run: npm run publish:beta + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }} + ACCESS_KEY_SECRET: ${{ secrets.ACCESS_KEY_SECRET }} + REGISTRY: https://registry.npmjs.org diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f2d94d62..d404d2178 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,15 +1,27 @@ -name: ci +name: CI on: [push] jobs: - build-and-publish: + build: runs-on: ubuntu-latest + strategy: + matrix: + node-version: [10.x] steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v2 + - uses: nelonoel/branch-name@v1 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 with: - node-version: 10 - registry-url: https://registry.npmjs.org/ - - run: npm i - - run: npm run ci \ No newline at end of file + node-version: ${{ matrix.node-version }} + - run: npm run setup + - run: npm run dependency:check + - run: npm run lint + - run: npm run test + - run: npm run version:check + - run: npm run coverage + env: + ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }} + ACCESS_KEY_SECRET: ${{ secrets.ACCESS_KEY_SECRET }} + CI: true diff --git a/.gitignore b/.gitignore index 4793df933..bfcea89ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1,40 @@ +# https://github.com/github/gitignore/blob/master/Node.gitignore +# Dependencies node_modules -.DS_Store -lerna-debug.log -npm-debug.log -mochawesome-report -.happypack +jspm_packages + +# Only keep yarn.lock in the root package-lock.json -yarn.lock -yarn-error.log -tempDir -coverage/ +*/**/yarn.lock -.eslintcache -databases -build -.vscode/ -.tmp/ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* -npmrc +# Coverage directory used by tools like istanbul +coverage +*.lcov -*~ -*.swp +# Others +.npm +.eslintcache +.idea .DS_Store -npm-debug.log -lerna-debug.log -npm-debug.log* -lib/ -es/ -dist/ -.idea/ +.happypack +.vscode +.tmp +*.swp +*.dia~ +*.temp.json + +# Packages +packages/*/lib/ + +# temp folder .ice +examples/*/.rax + +build diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..357fc60c5 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,8 @@ +node_modules/ +lib/ +dist/ +build/ +coverage/ +demo/ +es/ +.rax/ diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 000000000..23c8ce5a4 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,3 @@ +const { getPrettierConfig } = require('@iceworks/spec'); + +module.exports = getPrettierConfig('rax'); diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..dd11235d8 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,32 @@ +## Changelog + +### 3.0.7 (November 12, 2020) + +- Feat: support manually close store.([#3750](https://github.com/alibaba/ice/pull/3750)) +- Feat: support pages that are not in the `src/pages`.([#3750](https://github.com/alibaba/ice/pull/3750)) +- Feat: use `polyfill` field instead of `injectBabel` that can add polyfill by usage.([#3777](https://github.com/alibaba/ice/pull/3777)) +- Feat: add `eslint-reporting-webpack-plugin` for dev mode.([#3771](https://github.com/alibaba/ice/pull/3771)) +- Feat: support use miniapp compile mode in its runtime mode project.([#3766](https://github.com/alibaba/ice/pull/3766)) +- Feat: add rax-platform-loader.([raxjs/rax-scripts#480](https://github.com/raxjs/rax-scripts/pull/480)) +- Fix: `miniapp-native` dir copy logic.([#3761](https://github.com/alibaba/ice/pull/3761)) +- Fix: error when set `ssr: true`.([#3775](https://github.com/alibaba/ice/pull/3775)) +- Chore: remove rax-compile-config.([raxjs/rax-scripts#480](https://github.com/raxjs/rax-scripts/pull/480)) +- Chore: use `react-dev-utils/webpackHotDevClient` instead of `rax-compile-config/hmr`.([#3806](https://github.com/alibaba/ice/pull/3806)) +- Chore: change polyfill load settings.([raxjs/rax-scripts#480](https://github.com/raxjs/rax-scripts/pull/475)) +- Chore: update mini-css-extract-plugin version and set `esModule` to `false` as default.([raxjs/rax-scripts#475](https://github.com/raxjs/rax-scripts/pull/475)) +- Chore: unify the packaging mechanism of icejs and rax-app.([#3753](https://github.com/alibaba/ice/pull/3753)) +- Chore: change `compileDependencies` default value to `['']`.([#3802](https://github.com/alibaba/ice/pull/3802)) +- Enhance: open browser logic, now you can use ` -- --mpa-entry=home` to specify mpa entry.([#3798](https://github.com/alibaba/ice/pull/3798)) +- Docs: update router and change `compileDependencies` related docs.([raxjs/docs#42](https://github.com/raxjs/docs/pull/42) +) + + + +### 3.0.6 (October 30, 2020) + +- Feat: support browser history for web.([#3736](https://github.com/alibaba/ice/pull/3736)) +- Fix: windows path error.([#3695](https://github.com/alibaba/ice/pull/3695)) +- Fix: kraken/weex assets couldn't find.([#3736](https://github.com/alibaba/ice/pull/3736)) +- Enhance: format debug info.([#3736](https://github.com/alibaba/ice/pull/3736)) +- Feat: support miniapp compile config.([#3730](https://github.com/alibaba/ice/pull/3730)) + diff --git a/README.md b/README.md index c87ca2b4c..bf235ad38 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,107 @@ -# Rax Scripts - -Rax official engineering tools use `@alib/build-scripts` . `@alib/build-scripts` is based on webpack, supports various scenarios through the plugin system, and provides flexible webpack configuration capabilities based on `webpack-chain`. Users can realize engineering requirements by combining various plugins. +English | [简体中文](./README_zh-CN.md) + +

+ Downloads + Version + GitHub license + PRs Welcome + Gitter +

+ +> An universal framework based on Rax + +## Features + +- 🐂 **Universal**:Support Web/MiniApp/Kraken +- 🐴 **App lifecycle**:Provide usePageShow、usePageHide etc. +- 🐒 **Engineering**:Out of the box support for ES6+、TypeScript、Less、Sass、 CSS Modules,etc +- 🦊 **Routing**:Powerful Routing System, supports configured routing and conventions routing +- 🐯 **State management**:Built-in icestore, lightweight state management solution based on React Hooks +- 🐦 **Config**:Modes and Environment Variables configuration in the config file +- 🦁 **Application configuration**:Provide powerful and extensible application configuration +- 🐌 **Plugin system**:The plugin system provides rich features and allow the community to build reusable solutions +- 🐘 **TypeScript**:Support TypeScript ## Quick start -Install the latest version and initialize the project - -```bash -$ npm init rax my-app -``` - -## Use by installation +### Setup by Iceworks -```bash -$ npm install @alib/build-scripts --save-dev -``` -Configuration `build.json` - -```json -{ - "plugins": [ - ["build-plugin-rax-app", { "targets": ["web"]}] - ] -} -``` +We recommend creating a new icejs app using [Iceworks](https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks): -## How to Write Plugin +![demo](https://img.alicdn.com/tfs/TB13Wk.11H2gK0jSZJnXXaT1FXa-1478-984.png) +> See [Quick start by Iceworks](https://ice.work/docs/iceworks/quick-start) for more details. -`@alib/build-scripts` Itself will not perform any operations, but according plugins configured in build.json to execute engineering commands, for example, an ordinary webapp project configuration is as follows +### Setup by CLI -The plugin needs to export a function. The function will receive two parameters. The first is the pluginAPI provided by build scripts, and the second is the user-defined parameter passed to the plugin +We recommend creating a new icejs app using create-ice, which sets up everything automatically for you. To create a project, run: -```js -module.exports = (pluginAPI, options) => { - const { - context, - log, - onHook - } = pluginAPI; -}; +```bash +$ npm init ice ``` -### pluginAPI +`npm init ` is available in npm 6+ -* `context`: environment information (command、commandArgs、rootDir、userConfig、pkg) -* `onGetWebpackConfig`: You can modify the weback configuration in the form of weback chain -* `onHook`: Listening for command runtime events with `onHook` -* `log`: use npmlog -* `registerTask`: register webpack task -* `registerUserConfig`: Register the top-level configuration field in build.json for user field verification -* `registerCliOption`: cli config -* `setValue` & `getValue` Used to register variables in context for communication between plug-ins +Start local server to launch project: + +```bash +$ cd +$ npm install +$ npm run start # running on http://localhost:3333. +``` -### lifecycle +It's as simple as that! -start -* `before.start.load` Before getting the webpack configuration -* `before.start.run` Before webpack execution -* `after.start.compile` After compilation, every recompilation will be executed -* `before.start.devServer` After the middleware is loaded, before the webpack dev server is started -* `after.start.devServer` After the webpack dev server is started +## Examples -build +- [with-rax](https://github.com/raxjs/rax-scripts/tree/master/examples/with-rax) +- [with-rax-mpa](https://github.com/raxjs/rax-scripts/tree/master/examples/with-rax-mpa) +- [with-rax-store](https://github.com/raxjs/rax-scripts/tree/master/examples/with-rax-store) +- [with-rax-miniapp-compile](https://github.com/raxjs/rax-scripts/tree/master/examples/with-rax-miniapp-compile) -* `before.build.load` Before getting the webpack configuration -* `before.build.run` Before webpack execution -* `after.build.compile` End of build -## Plugin List +## Ecosystem -### build-plugin-rax-app +| Project | Version | Docs | Description | +|----------------|-----------------------------------------|--------------|-----------| +| [rax]| [![rax-status]][rax-package] | [docs][rax-docs] | Progressive React framework for building universal application| +| [rax-app] | [![rax-app-status]][rax-app-package] | [docs][rax-app-docs] | An universal framework based on rax.js | +| [miniapp] | [![miniapp-status]][miniapp-package] | [docs][miniapp-docs] | An mordern and high performance miniapp solution based on rax-app | +| [icestore] | [![icestore-status]][icestore-package] | [docs][icestore-docs] |Simple and friendly state for React like | +| [iceworks]| [![iceworks-status]][iceworks-package] | [docs][iceworks-docs] |Visual Intelligent Development Assistant| -Build Single-page application (SPA) -### build-plugin-rax-multi-pages +[rax]: https://github.com/alibaba/rax +[rax-app]: https://github.com/raxjs/rax-scripts +[miniapp]: https://github.com/raxjs/miniapp +[icestore]: https://github.com/ice-lab/icestore +[iceworks]: https://github.com/ice-lab/iceworks -Build Multi-page application (MPA) +[rax-status]: https://img.shields.io/npm/v/rax.svg +[rax-app-status]: https://img.shields.io/npm/v/rax-app.svg +[miniapp-status]: https://img.shields.io/npm/v/miniapp-render.svg +[icestore-status]: https://img.shields.io/npm/v/@ice/store.svg +[iceworks-status]: https://vsmarketplacebadge.apphb.com/version/iceworks-team.iceworks.svg -### build-plugin-rax-component +[rax-package]: https://npmjs.com/package/rax +[rax-app-package]: https://npmjs.com/package/rax-app +[miniapp-package]: https://npmjs.com/package/miniapp-render +[icestore-package]: https://npmjs.com/package/@ice/store +[iceworks-package]: https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks -Build universal component or universal API library +[rax-docs]: https://rax.js.org/docs/guide/about +[rax-app-docs]: https://rax.js.org/docs/guide/directory-structure +[miniapp-docs]: https://rax.js.org/miniapp +[icestore-docs]: https://github.com/ice-lab/icestore#icestore +[iceworks-docs]: https://ice.work/docs/iceworks/about -### build-plugin-rax-pwa +## Community -Build Progressive web application +| DingTalk community | GitHub issues | Gitter | +|-------------------------------------|--------------|---------| +| | [issues] | [gitter]| -### build-plugin-rax-ssr +[issues]: https://github.com/raxjs/rax-scripts/issues +[gitter]: https://gitter.im/rax-scripts/rax-scripts -Build Server-side rendering application (SSR) diff --git a/README_zh-CN.md b/README_zh-CN.md new file mode 100644 index 000000000..f7e6e4ecf --- /dev/null +++ b/README_zh-CN.md @@ -0,0 +1,116 @@ +[English](./README.md) | 简体中文 + +

+ Downloads + Version + GitHub license + PRs Welcome + Gitter +

+ +> 基于 Rax 的多端研发框架 + +## 特性 + +- 🐂 **多端**:支持 Web、小程序、Kraken 等容器运行 + +- 🐴 **完整的应用生命周期**:提供 usePageShow、usePageHide 等钩子 + +- 🐒 **工程**:开箱即用的工程配置,支持 ES6+、TypeScript、样式方案(Less/Sass/CSS Modules)等 + +- 🦊 **路由**:默认使用配置式路由,同时支持约定式路由 + +- 🐯 **数据流**:内置集成 icestore,基于 React Hooks 的轻量级状态管理方案 + +- 🐦 **环境配置**:内置集成 config, 支持多环境变量的配置 + +- 🦁 **应用配置**:提供强大的和可扩展的应用程序配置 + +- 🐌 **插件体系**:提供插件机制,可以扩展框架的核心功能 + +- 🐘 **TypeScript**:默认使用 TypeScript + + + +## 快速开始 + +### 使用 Iceworks 创建项目 + +我们推荐你安装 [Iceworks](https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks),然后通过该插件的引导进行项目的创建: + +![使用示例](https://img.alicdn.com/tfs/TB13Wk.11H2gK0jSZJnXXaT1FXa-1478-984.png) + +> 参考[《Iceworks 快速开始》](https://ice.work/docs/iceworks/quick-start)了解更多细节。 + +### 使用 CLI 创建项目 + +创建项目 + +```bash +$ npm init rax +``` + +`npm init ` 需要 npm 6+ 版本 + +启动项目 + +```bash +$ cd +$ npm install +$ npm run start # running on http://localhost:3333. +``` + +## 项目示例 + +- [with-rax](https://github.com/raxjs/rax-scripts/tree/master/examples/with-rax) +- [with-rax-mpa](https://github.com/raxjs/rax-scripts/tree/master/examples/with-rax-mpa) +- [with-rax-store](https://github.com/raxjs/rax-scripts/tree/master/examples/with-rax-store) +- [with-rax-miniapp-compile](https://github.com/raxjs/rax-scripts/tree/master/examples/with-rax-miniapp-compile) + + +## 生态 + +| Project | Version | Docs | Description | +|----------------|-----------------------------------------|--------------|-----------| +| [rax]| [![rax-status]][rax-package] | [docs][rax-docs] |用于构建移动跨端应用的渐进式 React 框架| +| [rax-app] | [![rax-app-status]][rax-app-package] | [docs][rax-app-docs] | 基于 Rax 的跨终端研发框架 | +| [miniapp] | [![miniapp-status]][miniapp-package] | [docs][miniapp-docs] | 基于 Rax 的小程序双引擎方案 | +| [icestore] | [![icestore-status]][icestore-package] | [docs][icestore-docs] | 简单友好的轻量级状态管理方案 | +| [iceworks]| [![iceworks-status]][iceworks-package] | [docs][iceworks-docs] | 可视化智能开发助手 | + + + +[rax]: https://github.com/alibaba/rax +[rax-app]: https://github.com/raxjs/rax-scripts +[miniapp]: https://github.com/raxjs/miniapp +[icestore]: https://github.com/ice-lab/icestore +[iceworks]: https://github.com/ice-lab/iceworks + +[rax-status]: https://img.shields.io/npm/v/rax.svg +[rax-app-status]: https://img.shields.io/npm/v/rax-app.svg +[miniapp-status]: https://img.shields.io/npm/v/miniapp-render.svg +[icestore-status]: https://img.shields.io/npm/v/@ice/store.svg +[iceworks-status]: https://vsmarketplacebadge.apphb.com/version/iceworks-team.iceworks.svg + +[rax-package]: https://npmjs.com/package/rax +[rax-app-package]: https://npmjs.com/package/rax-app +[miniapp-package]: https://npmjs.com/package/miniapp-render +[icestore-package]: https://npmjs.com/package/@ice/store +[iceworks-package]: https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks + +[rax-docs]: https://rax.js.org/docs/guide/about +[rax-app-docs]: https://rax.js.org/docs/guide/directory-structure +[miniapp-docs]: https://rax.js.org/miniapp +[icestore-docs]: https://github.com/ice-lab/icestore#icestore +[iceworks-docs]: https://ice.work/docs/iceworks/about + + +## 社区 + +| 钉钉群 | GitHub issues | Gitter | +|-------------------------------------|--------------|---------| +| | [issues] | [gitter]| + +[issues]: https://github.com/raxjs/rax-scripts/issues +[gitter]: https://gitter.im/rax-scripts/rax-scripts + diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index cfee805fa..000000000 --- a/babel.config.js +++ /dev/null @@ -1,19 +0,0 @@ -module.exports = { - 'presets': [ - [ - '@babel/preset-env', - { - 'loose': true, - 'targets': { - 'node': 'current', - }, - }, - ], - [ - '@babel/preset-react', - { - 'pragma': 'createElement' - } - ] - ] -}; diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..223d6d194 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,16 @@ + +comment: + layout: "reach, diff, flags, files" + behavior: default + require_changes: false + require_base: no + require_head: yes + branches: + - "master" + +coverage: + status: + project: + default: + threshold: 90% + patch: off diff --git a/commitlint.config.js b/commitlint.config.js index 422b19445..e53ad4038 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1 +1,5 @@ -module.exports = { extends: ['@commitlint/config-conventional'] }; +// .commitlintrc.js +const { getCommitlintConfig } = require('@iceworks/spec'); + +// getCommitlintConfig(rule: 'rax'|'react', customConfig?); +module.exports = getCommitlintConfig('rax'); diff --git a/examples/rax-app-ts/README.md b/examples/rax-app-ts/README.md deleted file mode 100644 index 585639347..000000000 --- a/examples/rax-app-ts/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# rax-app-ts - -## Getting Started - -### `npm run start` - -Runs the app in development mode. - -Open [http://localhost:9999](http://localhost:9999) to view it in the browser. - -The page will reload if you make edits. - -### `npm run build` - -Builds the app for production to the `build` folder. diff --git a/examples/rax-app-ts/build.json b/examples/rax-app-ts/build.json deleted file mode 100644 index 07d706b75..000000000 --- a/examples/rax-app-ts/build.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "inlineStyle": false, - "plugins": [ - [ - "build-plugin-rax-app", - { - "targets": [ - "web" - ] - } - ] - ] -} diff --git a/examples/rax-app-ts/src/app.ts b/examples/rax-app-ts/src/app.ts deleted file mode 100644 index 6e0875a07..000000000 --- a/examples/rax-app-ts/src/app.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { runApp } from 'rax-app'; -import appConfig from './app.json'; - -runApp(appConfig); \ No newline at end of file diff --git a/examples/rax-app-ts/src/components/LogoCss/index.tsx b/examples/rax-app-ts/src/components/LogoCss/index.tsx deleted file mode 100644 index 8d947266a..000000000 --- a/examples/rax-app-ts/src/components/LogoCss/index.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { createElement } from 'rax'; -import Image from 'rax-image'; - -import './index.css'; - -interface LogoProps { - uri: string; -} - -export default (props: LogoProps) => { - const { uri } = props; - const source = { uri }; - return ( -
- CSS 蓝色 - -
- ); -} diff --git a/examples/rax-app-ts/src/components/LogoCssModule/index.tsx b/examples/rax-app-ts/src/components/LogoCssModule/index.tsx deleted file mode 100644 index 6426b87d0..000000000 --- a/examples/rax-app-ts/src/components/LogoCssModule/index.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { createElement } from 'rax'; -import Image from 'rax-image'; - -import styles from './index.module.css'; - -interface LogoProps { - uri: string; -} - -export default (props: LogoProps) => { - const { uri } = props; - const source = { uri }; - return ( -
- CSS Modules 绿色 - -
- ); -} diff --git a/examples/rax-app-ts/src/components/LogoLess/index.less b/examples/rax-app-ts/src/components/LogoLess/index.less deleted file mode 100644 index 1d5131870..000000000 --- a/examples/rax-app-ts/src/components/LogoLess/index.less +++ /dev/null @@ -1,3 +0,0 @@ -.less-con { - background-color: red; -} diff --git a/examples/rax-app-ts/src/components/LogoLess/index.tsx b/examples/rax-app-ts/src/components/LogoLess/index.tsx deleted file mode 100644 index 558e2b0d9..000000000 --- a/examples/rax-app-ts/src/components/LogoLess/index.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import { createElement } from 'rax'; -import Image from 'rax-image'; - -// import './index.css'; -import './index.less'; - -// console.log(222, styles) - -interface LogoProps { - uri: string; -} - -export default (props: LogoProps) => { - const { uri } = props; - const source = { uri }; - return ( -
- LogoLess 红色 - -
- ); -} diff --git a/examples/rax-app-ts/src/components/LogoLessModule/index.tsx b/examples/rax-app-ts/src/components/LogoLessModule/index.tsx deleted file mode 100644 index 37c9c0fb2..000000000 --- a/examples/rax-app-ts/src/components/LogoLessModule/index.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import { createElement } from 'rax'; -import Image from 'rax-image'; - -// import './index.css'; -import styles from './index.module.less'; - -// console.log(222, styles) - -interface LogoProps { - uri: string; -} - -export default (props: LogoProps) => { - const { uri } = props; - const source = { uri }; - return ( -
- logoLessModule 黄色 - -
- ); -} diff --git a/examples/rax-app-ts/src/components/LogoSass/index.scss b/examples/rax-app-ts/src/components/LogoSass/index.scss deleted file mode 100644 index 925e6661f..000000000 --- a/examples/rax-app-ts/src/components/LogoSass/index.scss +++ /dev/null @@ -1,9 +0,0 @@ -.sass-con { - background-color: black; - color: white; -} -.logo { - width: 200rpx; - height: 180rpx; - margin-bottom: 20rpx; -} diff --git a/examples/rax-app-ts/src/components/LogoSass/index.tsx b/examples/rax-app-ts/src/components/LogoSass/index.tsx deleted file mode 100644 index b6d7190fe..000000000 --- a/examples/rax-app-ts/src/components/LogoSass/index.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { createElement } from 'rax'; -import Image from 'rax-image'; - -import './index.scss'; - -interface LogoProps { - uri: string; -} - -export default (props: LogoProps) => { - const { uri } = props; - const source = { uri }; - return ( -
- Sass 黑色 - -
- ); -} diff --git a/examples/rax-app-ts/src/components/LogoSassModule/index.tsx b/examples/rax-app-ts/src/components/LogoSassModule/index.tsx deleted file mode 100644 index a941fc88e..000000000 --- a/examples/rax-app-ts/src/components/LogoSassModule/index.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { createElement } from 'rax'; -import Image from 'rax-image'; -import styles from './index.module.scss'; - -interface LogoProps { - uri: string; -} - -export default (props: LogoProps) => { - const { uri } = props; - const source = { uri }; - return ( -
- logoSassModule purple - -
- ); -} diff --git a/examples/rax-app-ts/src/pages/Home/index.tsx b/examples/rax-app-ts/src/pages/Home/index.tsx deleted file mode 100644 index d332cb2cb..000000000 --- a/examples/rax-app-ts/src/pages/Home/index.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { createElement } from 'rax'; -import View from 'rax-view'; - -import Logo from '../../components/LogoCss'; -import Logo2 from '../../components/LogoCssModule'; -import Logo3 from '../../components/LogoLess'; -import Logo4 from '../../components/LogoLessModule'; -import Logo5 from '../../components/LogoSass'; -import Logo6 from '../../components/LogoSassModule'; - -export default function Home() { - const source = '//gw.alicdn.com/tfs/TB1MRC_cvb2gK0jSZK9XXaEgFXa-1701-1535.png'; - return ( - - - - - - - - - ); -} diff --git a/examples/rax-app-ts/src/typings.d.ts b/examples/rax-app-ts/src/typings.d.ts deleted file mode 100644 index ca6101b83..000000000 --- a/examples/rax-app-ts/src/typings.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -declare module '*.module.scss' { - const classes: { [key: string]: string }; - export default classes; -} -declare module '*.module.css' { - const classes: { [key: string]: string }; - export default classes; -} -declare module '*.module.less' { - const classes: { [key: string]: string }; - export default classes; -} diff --git a/examples/rax-component-js/README.md b/examples/rax-component-js/README.md deleted file mode 100644 index f94b5edd5..000000000 --- a/examples/rax-component-js/README.md +++ /dev/null @@ -1,37 +0,0 @@ -## rax-component-js - -## Install - -``` -$ npm install rax-component-js --save -``` - -## Usage - -``` -import MyComponent from 'rax-component-js'; -``` - -## API - -### Props - -|name|type|default|describe| -|:---------------|:--------|:----|:----------| -|name|String|''|describe| - -### Function - -|name|param|return|describe| -|:---------------|:--------|:----|:----------| -|name|Object|/|describe| - -## Example - -``` -import { createElement, render } from 'rax'; -import DriverUniversal from 'driver-universal'; -import MyComponent from 'rax-component-js'; - -render(, document.body, { driver: DriverUniversal }); -``` diff --git a/examples/rax-component-js/build.json b/examples/rax-component-js/build.json deleted file mode 100644 index 05be5c54d..000000000 --- a/examples/rax-component-js/build.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "plugins": [ - [ - "../../packages/build-plugin-rax-component", - { - "type": "rax", - "targets": ["web"] - } - ], - "../../packages/build-plugin-multi-demo-portal" - ] -} diff --git a/examples/rax-component-js/demo/advance.md b/examples/rax-component-js/demo/advance.md deleted file mode 100644 index ddb7cd68c..000000000 --- a/examples/rax-component-js/demo/advance.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -order: 2 ---- - -# Advance - -advance usage - -```jsx -import { createElement, render } from 'rax'; -import DriverUniversal from 'driver-universal'; -import MyComponent from 'rax-component-js'; - -render(, document.body, { driver: DriverUniversal }); -``` diff --git a/examples/rax-component-js/demo/basic.md b/examples/rax-component-js/demo/basic.md deleted file mode 100644 index 89239090e..000000000 --- a/examples/rax-component-js/demo/basic.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -order: 1 ---- - -# Basic - -basic usage - -```jsx -import { createElement, render } from 'rax'; -import DriverUniversal from 'driver-universal'; -import MyComponent from 'rax-component-js'; - -render(, document.body, { driver: DriverUniversal }); -``` diff --git a/examples/rax-component-js/package.json b/examples/rax-component-js/package.json deleted file mode 100644 index 850bf6d5f..000000000 --- a/examples/rax-component-js/package.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "name": "rax-component-js", - "author": "rax", - "version": "0.0.0", - "description": "", - "main": "lib/index.js", - "module": "es/index.js", - "miniappConfig": { - "main": "lib/miniapp/index", - "main:wechat": "lib/wechat-miniprogram/index" - }, - "files": [ - "dist", - "es", - "lib" - ], - "keywords": [ - "Rax", - "rax-component" - ], - "engines": { - "npm": ">=3.0.0" - }, - "peerDependencies": { - "rax": "^1.1.0" - }, - "scripts": { - "start": "build-scripts start", - "build": "build-scripts build" - }, - "dependencies": { - "rax-text": "^1.0.0", - "rax-view": "^1.0.0" - }, - "devDependencies": { - "@alib/build-scripts": "^0.1.0", - "driver-universal": "^3.1.3", - "rax": "^1.1.0", - "rax-test-renderer": "^1.0.0" - } -} diff --git a/examples/rax-component-js/src/index.jsx b/examples/rax-component-js/src/index.jsx deleted file mode 100644 index b7cc1a56a..000000000 --- a/examples/rax-component-js/src/index.jsx +++ /dev/null @@ -1,13 +0,0 @@ -import { createElement } from 'rax'; -import View from 'rax-view'; -import Text from 'rax-text'; - -const MyComponent = (props) => { - return ( - - Hello World! - - ); -}; - -export default MyComponent; diff --git a/examples/rax-component-ts/README.md b/examples/rax-component-ts/README.md deleted file mode 100644 index 2a739ce26..000000000 --- a/examples/rax-component-ts/README.md +++ /dev/null @@ -1,37 +0,0 @@ -## rax-component - -## Install - -``` -$ npm install rax-component --save -``` - -## Usage - -``` -import MyComponent from 'rax-component'; -``` - -## API - -### Props - -|name|type|default|describe| -|:---------------|:--------|:----|:----------| -|name|String|''|describe| - -### Function - -|name|param|return|describe| -|:---------------|:--------|:----|:----------| -|name|Object|/|describe| - -## Example - -``` -import { createElement, render } from 'rax'; -import DriverUniversal from 'driver-universal'; -import MyComponent from 'rax-component'; - -render(, document.body, { driver: DriverUniversal }); -``` diff --git a/examples/rax-component-ts/build.json b/examples/rax-component-ts/build.json deleted file mode 100644 index 05be5c54d..000000000 --- a/examples/rax-component-ts/build.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "plugins": [ - [ - "../../packages/build-plugin-rax-component", - { - "type": "rax", - "targets": ["web"] - } - ], - "../../packages/build-plugin-multi-demo-portal" - ] -} diff --git a/examples/rax-component-ts/demo/advance.md b/examples/rax-component-ts/demo/advance.md deleted file mode 100644 index 69df6d486..000000000 --- a/examples/rax-component-ts/demo/advance.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -order: 2 ---- - -# Advance - -advance usage - -```jsx -import { createElement, render } from 'rax'; -import DriverUniversal from 'driver-universal'; -import MyComponent from 'rax-component'; - -render(, document.body, { driver: DriverUniversal }); -``` diff --git a/examples/rax-component-ts/demo/basic.md b/examples/rax-component-ts/demo/basic.md deleted file mode 100644 index 91b9e22d8..000000000 --- a/examples/rax-component-ts/demo/basic.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -order: 1 ---- - -# Basic - -basic usage - -```jsx -import { createElement, render } from 'rax'; -import DriverUniversal from 'driver-universal'; -import MyComponent from 'rax-component'; - -render(, document.body, { driver: DriverUniversal }); -``` diff --git a/examples/rax-component-ts/package.json b/examples/rax-component-ts/package.json deleted file mode 100644 index 55067cbe9..000000000 --- a/examples/rax-component-ts/package.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "name": "rax-component", - "author": "rax", - "version": "0.0.0", - "description": "", - "main": "lib/index.js", - "module": "es/index.js", - "miniappConfig": { - "main": "lib/miniapp/index", - "main:wechat": "lib/wechat-miniprogram/index" - }, - "files": [ - "dist", - "es", - "lib", - "types" - ], - "keywords": [ - "Rax", - "rax-component" - ], - "engines": { - "npm": ">=3.0.0" - }, - "peerDependencies": { - "rax": "^1.1.0" - }, - "scripts": { - "start": "build-scripts start", - "build": "build-scripts build" - }, - "dependencies": { - "rax-text": "^1.0.0", - "rax-view": "^1.0.0" - }, - "devDependencies": { - "typescript": "^3.7.5", - "@types/rax": "^1.0.0", - "@alib/build-scripts": "^0.1.0", - "driver-universal": "^3.1.0", - "rax": "^1.1.0", - "rax-test-renderer": "^1.0.0" - } -} diff --git a/examples/rax-component-ts/src/index.tsx b/examples/rax-component-ts/src/index.tsx deleted file mode 100644 index 6edce22f8..000000000 --- a/examples/rax-component-ts/src/index.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { createElement } from 'rax'; -import View from 'rax-view'; -import Text from 'rax-text'; - -interface IProps { - type: string; -}; - -const MyComponent = (props: IProps) => { - return ( - - Hello World! - - ); -}; - -export default MyComponent; diff --git a/examples/rax-component-ts/tsconfig.json b/examples/rax-component-ts/tsconfig.json deleted file mode 100644 index 65a160eaf..000000000 --- a/examples/rax-component-ts/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - "module": "esNext", - "target": "es2015", - "jsx": "preserve", - "jsxFactory": "createElement", - "moduleResolution": "node", - "alwaysStrict": true, - "sourceMap": false, - "allowSyntheticDefaultImports": true, - "suppressImplicitAnyIndexErrors": true, - "removeComments": false, - "preserveConstEnums": true, - "experimentalDecorators": true, - "noImplicitReturns": true, - "noUnusedLocals": true, - "noUnusedParameters": false, - "noImplicitAny": false, - "noImplicitThis": false, - "resolveJsonModule": true, - "outDir": "lib", - "rootDir": "src", - "baseUrl": "." - }, - "include": ["src/**/*"], - "exclude": ["node_modules", "lib"] -} diff --git a/examples/with-rax-miniapp-compile/README.md b/examples/with-rax-miniapp-compile/README.md new file mode 100644 index 000000000..ac0dcea2c --- /dev/null +++ b/examples/with-rax-miniapp-compile/README.md @@ -0,0 +1,3 @@ +# with rax miniapp compile + +https://github.com/ice-lab/icejs/tree/master/examples diff --git a/examples/with-rax-miniapp-compile/build.json b/examples/with-rax-miniapp-compile/build.json new file mode 100644 index 000000000..5cae02f9d --- /dev/null +++ b/examples/with-rax-miniapp-compile/build.json @@ -0,0 +1,6 @@ +{ + "targets": ["miniapp"], + "miniapp": { + "buildType": "compile" + } +} diff --git a/examples/with-rax-miniapp-compile/package.json b/examples/with-rax-miniapp-compile/package.json new file mode 100644 index 000000000..7a55f71af --- /dev/null +++ b/examples/with-rax-miniapp-compile/package.json @@ -0,0 +1,22 @@ +{ + "name": "with-rax-miniapp-compile", + "description": "rax example", + "dependencies": { + "rax": "^1.1.0", + "rax-document": "^0.1.0", + "rax-image": "^2.0.0", + "rax-link": "^1.0.1", + "rax-text": "^1.0.0", + "rax-view": "^1.0.0" + }, + "devDependencies": { + "@types/rax": "^1.0.0" + }, + "scripts": { + "start": "rax-app start", + "build": "rax-app build" + }, + "engines": { + "node": ">=8.0.0" + } +} diff --git a/examples/with-rax-miniapp-compile/src/app.json b/examples/with-rax-miniapp-compile/src/app.json new file mode 100644 index 000000000..21d71dd98 --- /dev/null +++ b/examples/with-rax-miniapp-compile/src/app.json @@ -0,0 +1,15 @@ +{ + "routes": [ + { + "path": "/", + "source": "pages/Home/index" + }, + { + "path": "/about", + "source": "/pages/About/index" + } + ], + "window": { + "title": "Rax App" + } +} diff --git a/examples/with-rax-miniapp-compile/src/app.tsx b/examples/with-rax-miniapp-compile/src/app.tsx new file mode 100644 index 000000000..d7efb2c11 --- /dev/null +++ b/examples/with-rax-miniapp-compile/src/app.tsx @@ -0,0 +1,17 @@ +import { createElement } from 'rax'; +import { runApp } from 'rax-app'; + +runApp({ + app: { + // 生命周期 + onShow() { + console.log('app show...'); + }, + onHide() { + console.log('app hide...'); + }, + onLaunch() { + console.log('app launch...'); + }, + }, +}); diff --git a/examples/rax-app-ts/src/components/LogoCssModule/index.module.css b/examples/with-rax-miniapp-compile/src/components/Logo/index.css similarity index 63% rename from examples/rax-app-ts/src/components/LogoCssModule/index.module.css rename to examples/with-rax-miniapp-compile/src/components/Logo/index.css index 67313dec4..2f8d8d114 100644 --- a/examples/rax-app-ts/src/components/LogoCssModule/index.module.css +++ b/examples/with-rax-miniapp-compile/src/components/Logo/index.css @@ -1,8 +1,5 @@ -.con { - background-color: green; -} .logo { width: 200rpx; height: 180rpx; margin-bottom: 20rpx; -} +} \ No newline at end of file diff --git a/examples/with-rax-miniapp-compile/src/components/Logo/index.tsx b/examples/with-rax-miniapp-compile/src/components/Logo/index.tsx new file mode 100644 index 000000000..2ecb40c6f --- /dev/null +++ b/examples/with-rax-miniapp-compile/src/components/Logo/index.tsx @@ -0,0 +1,23 @@ +import { createElement, Component } from 'rax'; +import Image from 'rax-image'; +import { withRouter } from 'rax-app'; + +import './index.css'; + +// eslint-disable-next-line react/prefer-stateless-function +class Logo extends Component { + render() { + const source = { + uri: `${process.env.PUBLIC_URL}/rax.png`, + }; + console.log('with router =>', this.props); + return ( + + ); + } +} + +export default withRouter(Logo); diff --git a/examples/with-rax-miniapp-compile/src/document/index.jsx b/examples/with-rax-miniapp-compile/src/document/index.jsx new file mode 100644 index 000000000..9b3cc064e --- /dev/null +++ b/examples/with-rax-miniapp-compile/src/document/index.jsx @@ -0,0 +1,22 @@ +import { createElement } from 'rax'; +import { Root, Style, Script, Data } from 'rax-document'; + +function Document(props) { + return ( + + + + + @ali/demo-app + - - - - - diff --git a/packages/build-plugin-multi-demo-portal/src/config/template/portal.hbs b/packages/build-plugin-multi-demo-portal/src/config/template/portal.hbs deleted file mode 100644 index c1fed8f49..000000000 --- a/packages/build-plugin-multi-demo-portal/src/config/template/portal.hbs +++ /dev/null @@ -1,169 +0,0 @@ -import { createElement, render, useState, useEffect } from "rax"; -import DriverUniversal from "driver-universal"; - -const demos = [ - {{#each demos}} - { - name: '{{name}}', - title: '{{title}}', - js: `{{{code}}}`, - desc:`{{{desc}}}` - }, - {{/each}} -]; - -const DemoBlock = ({ js, css, name, title, desc, active, onClick }) => { - const [open, setOpen] = useState(false); - const wrapperStyle = {maxHeight: open ? '800px' : '150px'}; - const jsxHtml = { __html: js || '' }; - const cssHtml = { __html: css || '' }; - const descHtml = {__html: desc || ''}; - const targets = '{{targets}}'.split(','); - const isWebEnable = ~targets.indexOf('web'); - const isWeexEnable = ~targets.indexOf('weex'); - const isMiniappEnable = ~targets.indexOf('miniapp'); - - return ( - - ); -}; - -const Device = ({ children }) => ( -
- - - - - - - - - - -
{children}
-
-); - -const DemoBlocks = ({active:activeProp, onChange}) => { - const [active, setActive ] = useState(activeProp); - - useEffect(() => { - setActive(activeProp); - }, [active]); - - return demos.map((demo, index)=>{ - return ( - { - setActive(demo.name); - onChange(demo.name); - }} - /> - ); - }) -} - -function Portal(props){ - const docHtml = {__html: `{{{docHtml}}}` || ''}; - const iframeStyle = { width: '100%', height: '760px', border: 'none' }; - const [active, setActive ] = useState(demos && demos[0] && demos[0].name); - const handleChange = (demo) => { - setActive(demo); - } - - return ( -
-
-

{props.title}

-

DEMO

-
- -
-
-
-
-
- - - -
- ); -} - -render(, null, { driver: DriverUniversal }); - diff --git a/packages/build-plugin-multi-demo-portal/src/config/utils/generatePortalJs.js b/packages/build-plugin-multi-demo-portal/src/config/utils/generatePortalJs.js deleted file mode 100644 index d40945203..000000000 --- a/packages/build-plugin-multi-demo-portal/src/config/utils/generatePortalJs.js +++ /dev/null @@ -1,38 +0,0 @@ -const path = require('path'); -const hbs = require('handlebars'); -const fs = require('fs-extra'); -const htmlDecode = require('js-htmlencode').htmlDecode; -const parseMd = require('./parseMarkdown'); - -const PORTAL_TMPL_PATH = path.resolve(__dirname, '../template/portal.hbs'); - -function compile(hbsPath) { - const hbsTemplateContent = fs.readFileSync(hbsPath, 'utf-8'); - const compileTemplateContent = hbs.compile(hbsTemplateContent); - - return compileTemplateContent; -} - -module.exports = function({ - filename = 'index.js', - rootDir = process.cwd(), - componentName = 'component', - params, -}) { - const compileTemplateContent = compile(PORTAL_TMPL_PATH); - const readmeFilePath = path.resolve(rootDir, './README.md'); - const result = parseMd(componentName, readmeFilePath); - const docHtml = result.body; - - const tempDir = path.join(rootDir, './node_modules'); - const jsPath = path.join(tempDir, filename); - - const jsTemplateContent = compileTemplateContent({ - ...params, - title: result.meta.title, - docHtml: htmlDecode(docHtml), - }); - fs.writeFileSync(jsPath, jsTemplateContent); - - return jsPath; -}; diff --git a/packages/build-plugin-multi-demo-portal/src/config/utils/getBuildTargets.js b/packages/build-plugin-multi-demo-portal/src/config/utils/getBuildTargets.js deleted file mode 100644 index 582ce2315..000000000 --- a/packages/build-plugin-multi-demo-portal/src/config/utils/getBuildTargets.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = (userConfig = []) => { - let targets = []; - - userConfig.plugins.forEach(config => { - if ( - Array.isArray(config) && - config[0] === 'build-plugin-rax-component' && - config[1] && - Array.isArray(config[1].targets) - ) { - targets = config[1].targets; - } - }); - - return targets; -}; diff --git a/packages/build-plugin-multi-demo-portal/src/config/utils/getDemos.js b/packages/build-plugin-multi-demo-portal/src/config/utils/getDemos.js deleted file mode 100644 index bef53715a..000000000 --- a/packages/build-plugin-multi-demo-portal/src/config/utils/getDemos.js +++ /dev/null @@ -1,44 +0,0 @@ -const path = require('path'); -const glob = require('glob'); -const fs = require('fs-extra'); -const parseMd = require('../utils/parseMarkdown'); -const Prism = require('prismjs'); - -module.exports = function(rootDir) { - const demos = []; - // read demos - glob.sync(path.resolve(rootDir, 'demo/*.{js,jsx,md}')).forEach(filePath => { - const name = filePath.substring( - filePath.lastIndexOf('/') + 1, - Math.max(filePath.indexOf('.js'), filePath.indexOf('.md')) - ); - const demo = { - name, - filePath, - title: name, - order: 0, - js: '', - desc: '' - }; - - if (/\.md$/.test(filePath)) { - const result = parseMd(name, filePath); - - demo.title = result.meta.title; - demo.js = result.js; - demo.order = result.meta.order; - demo.desc = result.body; - } else { - demo.js = fs.readFileSync(filePath, 'utf-8'); - } - - demos.push({ - ...demo, - code: Prism.highlight(demo.js, Prism.languages.javascript, 'javascript') - }); - }); - - return demos.sort((demo1, demo2) => { - return demo1.order > demo2.order ? 1 : -1; - }); -}; diff --git a/packages/build-plugin-multi-demo-portal/src/config/utils/parseMarkdown.js b/packages/build-plugin-multi-demo-portal/src/config/utils/parseMarkdown.js deleted file mode 100644 index 547844a7f..000000000 --- a/packages/build-plugin-multi-demo-portal/src/config/utils/parseMarkdown.js +++ /dev/null @@ -1,119 +0,0 @@ -const remarkAbstract = require('remark'); -const colors = require('chalk'); -const fs = require('fs-extra'); -const marked = require('marked'); -const Prism = require('prismjs'); - -const remark = remarkAbstract(); - -/** - * Parse demo markdown - * @param name - * @param filePath - * @returns { Object } result { meta: {name, order, title, desc } } - */ -module.exports = (name, filePath) => { - const result = { - meta: { - name, - order: 0, - title: name - }, - js: null, - css: null, - html: null, - body: null - }; - - let content = fs.readFileSync(filePath).toString(); - - if (!content) return result; - - const AST = remark.parse(content.replace(/^---(.|\n)*---/gim, '')); - - if (!AST || !AST.children) { - colors.yellow(`Can not parse the demo md: ${filePath}`); - return result; - } - - // meta - const metaReg = /---(.|\n)*---/g; - const metaArray = content.match(metaReg); - - if (metaArray && metaArray.length > 0) { - content = content.replace(metaReg, ''); - metaArray.forEach(metaStr => { - if (!metaStr) return; - metaStr = metaStr.replace(/---/g, ''); - metaStr - .split('\n') - .map(str => str.trim()) - .filter(str => !!str) - .forEach(metaItemStr => { - const index = metaItemStr.indexOf(':'); - - result.meta[ - metaItemStr.substring(0, index).trim() - ] = metaItemStr.substring(index + 1).trim(); - }); - }); - } - - // title - const titleNode = AST.children.find( - child => child.type === 'heading' && child.depth === 1 - ); - if (titleNode && titleNode.children && titleNode.children[0]) { - result.meta.title = titleNode.children[0].value; - } - - // code - const body = AST.children; - - const jsNode = body.find( - child => child.type === 'code' && ['js', 'jsx'].indexOf(child.lang) > -1 - ); - if (jsNode) { - result.js = jsNode.value; - } - - const cssNode = body.find( - child => child.type === 'code' && child.lang === 'css' - ); - if (cssNode) { - result.css = cssNode.value; - } - - const htmlNode = body.find( - child => child.type === 'code' && child.lang === 'html' - ); - - if (htmlNode) { - result.html = htmlNode.value; - } - - const bodyContent = body.map(child => { - if ( - child.type === 'code' && - ['js', 'jsx', 'css', 'html'].indexOf(child.lang) > 0 - ) { - return '\n'; - } else if (child.type === 'code') { - return `
${Prism.highlight(
-        child.value,
-        Prism.languages.javascript,
-        'javascript'
-      )}
`; - } else if (!(child.type === 'heading' && child.depth === 1)) { - return marked(remark.stringify(child)); - } else { - return '\n'; - } - }); - - if (bodyContent) { - result.body = bodyContent.join('\n'); - } - - return result; -}; diff --git a/packages/build-plugin-multi-demo-portal/src/dev.js b/packages/build-plugin-multi-demo-portal/src/dev.js deleted file mode 100644 index 9214ccbb6..000000000 --- a/packages/build-plugin-multi-demo-portal/src/dev.js +++ /dev/null @@ -1,56 +0,0 @@ -const ip = require('ip'); -const consoleClear = require('console-clear'); -const chalk = require('chalk'); -const { handleWebpackErr } = require('rax-compile-config'); - -module.exports = (api, options = {}) => { - const { registerTask, context, onHook } = api; - - // set dev config - const getDev = require('./config/getDev'); - const config = getDev(context, options); - - registerTask('component-multi-demo-portal', config); - - let devUrl = ''; - let devCompletedArr = []; - - function devCompileLog() { - consoleClear(true); - let { err, stats } = devCompletedArr[0]; - - devCompletedArr.forEach(devInfo => { - if (devInfo.err || devInfo.stats.hasErrors()) { - err = devInfo.err; - stats = devInfo.stats; - } - }); - - devCompletedArr = []; - - if (!handleWebpackErr(err, stats)) { - return; - } - - const portalUrl = `${devUrl}portal`.replace(/^http:\/\/localhost/gi, function(match) { - // Called when matched - try { - return `http://${ip.address()}`; - } catch (error) { - console.log(chalk.yellow(`Get local IP address failed: ${error.toString()}`)); - return match; - } - }); - - console.log(chalk.green('Multi-page portal has been started at:')); - console.log(); - console.log(' ', chalk.underline.white(portalUrl)); - console.log(); - } - - onHook('after.start.compile', async args => { - devUrl = args.url; - devCompletedArr.push(args); - devCompileLog(); - }); -}; diff --git a/packages/build-plugin-multi-demo-portal/src/index.js b/packages/build-plugin-multi-demo-portal/src/index.js deleted file mode 100644 index fb2813d3e..000000000 --- a/packages/build-plugin-multi-demo-portal/src/index.js +++ /dev/null @@ -1,27 +0,0 @@ -const chalk = require('chalk'); -const dev = require('./dev'); -const build = require('./build'); - -module.exports = (api, options = {}) => { - const { command, userConfig } = api.context; - const firstPlugin = userConfig.plugins[0]; - const firstPluginName = Array.isArray(firstPlugin) ? firstPlugin[0] : firstPlugin; - - if (!/build-plugin-rax-component/.test(firstPluginName)) { - console.error( - chalk.red( - '[build-plugin-multi-demo-portal] need build-plugin-rax-component to be set in build.json', - ), - ); - process.exit(1); - } - - // set dev config - if (command === 'start') { - dev(api, options); - } - - if (command === 'build') { - build(api, options); - } -}; diff --git a/packages/build-plugin-multi-demo-portal/src/loaders/MarkdownLoader/index.js b/packages/build-plugin-multi-demo-portal/src/loaders/MarkdownLoader/index.js deleted file mode 100644 index 4a425fc9d..000000000 --- a/packages/build-plugin-multi-demo-portal/src/loaders/MarkdownLoader/index.js +++ /dev/null @@ -1,12 +0,0 @@ -const path = require('path'); -const parseMd = require('../../config/utils/parseMarkdown'); - -module.exports = function() { - const resourcePath = this.resourcePath; - const ext = path.extname(resourcePath); - const name = path.basename(resourcePath, ext); - - const result = parseMd(name, resourcePath); - - return result.js; -}; diff --git a/packages/build-plugin-rax-app/package.json b/packages/build-plugin-rax-app/package.json deleted file mode 100644 index 0efcd4ec9..000000000 --- a/packages/build-plugin-rax-app/package.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "build-plugin-rax-app", - "version": "5.2.9", - "description": "rax app base plugins", - "main": "src/index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [ - "plugin", - "rax" - ], - "author": "", - "license": "MIT", - "peerDependencies": { - "@alib/build-scripts": "^0.1.0", - "rax": "^1.0.0" - }, - "dependencies": { - "@babel/core": "7.2.0", - "@babel/generator": "^7.9.6", - "@reactml/loader": "^0.1.2", - "autoprefixer": "^9.4.3", - "babel-loader": "8.0.4", - "case-sensitive-paths-webpack-plugin": "^2.1.2", - "chalk": "^2.4.2", - "chokidar": "^3.3.1", - "console-clear": "^1.1.1", - "copy-webpack-plugin": "^5.0.4", - "css-loader": "^3.4.2", - "deepmerge": "^4.0.0", - "enhanced-resolve": "^4.2.0", - "error-stack-tracey": "^0.1.1", - "fs-extra": "^8.1.0", - "image-source-loader": "^0.6.5", - "ip": "^1.1.5", - "jsx2mp-runtime": "^0.4.1", - "klaw-sync": "^6.0.0", - "less": "^3.9.0", - "less-loader": "^5.0.0", - "loader-utils": "^1.1.0", - "lodash": "^4.17.15", - "memory-fs": "^0.5.0", - "mini-css-extract-plugin": "^0.9.0", - "miniapp-builder-shared": "0.1.6", - "miniapp-compile-config": "0.1.2", - "miniapp-runtime-config": "0.1.3", - "null-loader": "^3.0.0", - "optimize-css-assets-webpack-plugin": "^5.0.1", - "postcss": "^7.0.17", - "postcss-import": "^12.0.1", - "postcss-loader": "^3.0.0", - "postcss-plugin-rpx2vw": "^0.0.1", - "postcss-preset-env": "^6.6.0", - "qrcode-terminal": "^0.12.0", - "qs": "^6.9.1", - "rax-babel-config": "^0.1.0", - "rax-compile-config": "0.2.16", - "rax-multi-pages-settings": "^0.1.1", - "rax-quickapp-webpack-plugin": "^1.0.0", - "rax-server-renderer": "^1.0.0", - "rax-webpack-config": "^0.1.0", - "sass-loader": "^8.0.2", - "stylesheet-loader": "^0.8.0", - "terser": "^4.6.4", - "terser-webpack-plugin": "^2.1.3", - "ts-loader": "^5.3.3", - "typescript": "^3.2.4", - "webpack": "^4.27.1", - "webpack-bundle-analyzer": "^3.4.1", - "webpack-chain": "^6.0.0", - "webpack-sources": "^1.3.0" - } -} diff --git a/packages/build-plugin-rax-app/src/build.js b/packages/build-plugin-rax-app/src/build.js deleted file mode 100644 index 9faec4c78..000000000 --- a/packages/build-plugin-rax-app/src/build.js +++ /dev/null @@ -1,120 +0,0 @@ -const path = require('path'); -const chalk = require('chalk'); -const consoleClear = require('console-clear'); -const { handleWebpackErr } = require('rax-compile-config'); -const checkQuickAppEnv = require('rax-quickapp-webpack-plugin'); -const { setConfig } = require('rax-multi-pages-settings'); - -const processRelativePublicPath = require('./config/processRelativePublicPath'); - -const { WEB, WEEX, MINIAPP, KRAKEN, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, QUICKAPP } = require('./constants'); - -module.exports = ({ onGetWebpackConfig, registerTask, context, onHook }, options = {}) => { - const { targets = [], type = 'spa' } = options; - - targets.forEach(async(target) => { - // Process relative publicPath. - onGetWebpackConfig(target, (config) => { - // Set MPA config - // Should setConfig in onGetWebpackConfig method. Need to get SSR params and all build targets. - if ( - type === 'mpa' - && (target === 'web' || target === 'weex') - ) { - setConfig(config, context, targets, target); - } - processRelativePublicPath(target, config); - }); - - if ([WEB, WEEX, KRAKEN].includes(target)) { - const getBase = require(`./config/${target}/getBase`); - registerTask(target, getBase(context, target, options)); - } - - if ([MINIAPP, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, QUICKAPP].includes(target)) { - if (options[target] && options[target].buildType === 'runtime') { - const getBase = require('./config/miniapp/runtime/getBase'); - registerTask(target, getBase(context, target, options, onGetWebpackConfig)); - } else { - const getBase = require('./config/miniapp/compile/getBase'); - registerTask(target, getBase(context, target, options, onGetWebpackConfig)); - } - } - }); - - onHook('after.build.compile', ({ err, stats }) => { - consoleClear(true); - if (!handleWebpackErr(err, stats)) { - return; - } - logBuildResult(targets, context); - }); -}; - -/** - * Log build result - * @param {array} targets - * @param {object} context - */ -function logBuildResult(targets = [], context = {}) { - const { rootDir, userConfig = {} } = context; - const { outputDir } = userConfig; - - console.log(chalk.green('Rax build finished:')); - console.log(); - - if (targets.includes(WEB)) { - console.log(chalk.green('[Web] Bundle at:')); - console.log(' ', chalk.underline.white(path.resolve(rootDir, outputDir, WEB))); - console.log(); - } - - if (targets.includes(WEEX)) { - console.log(chalk.green('[Weex] Bundle at:')); - console.log(' ', chalk.underline.white(path.resolve(rootDir, outputDir, WEEX))); - console.log(); - } - - if (targets.includes(KRAKEN)) { - console.log(chalk.green('[Kraken] Bundle at:')); - console.log(' ', chalk.underline.white(path.resolve(rootDir, outputDir, KRAKEN))); - console.log(); - } - - if (targets.includes(MINIAPP)) { - console.log(chalk.green('[Alibaba MiniApp] Bundle at:')); - console.log(' ', chalk.underline.white(getOutputPath(context, MINIAPP))); - console.log(); - } - - if (targets.includes(WECHAT_MINIPROGRAM)) { - console.log(chalk.green('[WeChat MiniProgram] Bundle at:')); - console.log(' ', chalk.underline.white(getOutputPath(context, WECHAT_MINIPROGRAM))); - console.log(); - } - - if (targets.includes(BYTEDANCE_MICROAPP)) { - console.log(chalk.green('[ByteDance MicroApp] Bundle at:')); - console.log(' ', chalk.underline.white(getOutputPath(context, BYTEDANCE_MICROAPP))); - console.log(); - } - - if (targets.includes(QUICKAPP)) { - // Check for quick app's environment - const quickAppDist = getOutputPath(context, QUICKAPP); - checkQuickAppEnv({ - workDirectory: process.cwd(), - distDirectory: quickAppDist, - }); - console.log(chalk.green('[Quick App] Use quick app developer tools to open the following folder:')); - console.log(' ', chalk.underline.white(quickAppDist)); - console.log(); - } -} - - -function getOutputPath(context, target) { - const { rootDir, userConfig } = context; - const { outputDir = 'build' } = userConfig; - return path.resolve(rootDir, outputDir, target); -} diff --git a/packages/build-plugin-rax-app/src/config/getWebpackBase.js b/packages/build-plugin-rax-app/src/config/getWebpackBase.js deleted file mode 100644 index 1f015f73b..000000000 --- a/packages/build-plugin-rax-app/src/config/getWebpackBase.js +++ /dev/null @@ -1,84 +0,0 @@ -const fs = require('fs-extra'); -const path = require('path'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); -const getWebpackBase = require('rax-webpack-config'); -const getBabelConfig = require('rax-babel-config'); - -module.exports = (context, options = {}, target) => { - const { rootDir, command } = context; - const { processBar } = options; - - const babelConfig = getBabelConfig({ - styleSheet: true, - ...options, - }); - - const config = getWebpackBase({ - ...context, - processBar: processBar || { - name: target - }, - babelConfig: babelConfig, - }); - - config.target('web'); - config.context(rootDir); - - config.resolve.extensions - .merge([ - '.rml', - ]); - - // Process app.json file - config.module.rule('appJSON') - .type('javascript/auto') - .test(/app\.json$/) - .use('babel') - .loader(require.resolve('babel-loader')) - .options(babelConfig) - .end() - .use('loader') - .loader(require.resolve('../loaders/AppConfigLoader')); - - // ReactML support - config.module.rule('rml') - .test(/\.rml$/i) - .use('rml') - .loader(require.resolve('@reactml/loader')) - .options({ - renderer: 'rax', - inlineStyle: context.userConfig.inlineStyle, - }) - .end(); - - config.module.rule('tsx') - .use('ts') - .loader(require.resolve('ts-loader')) - .options({ - transpileOnly: true, - }) - .end() - .use('platform') - .loader(require.resolve('rax-compile-config/src/platformLoader')); - - config.module.rule('jsx') - .test(/\.(js|mjs|jsx)$/) - .use('platform') - .loader(require.resolve('rax-compile-config/src/platformLoader')); - - - const copyWebpackPluginPatterns = [{ from: 'src/public', to: `${target}/public` }]; - - if (command === 'start') { - // MiniApp usually use `./public/xxx.png` as file src. - // Dev Server start with '/'. if you want to use './public/xxx.png', should copy public to the root. - copyWebpackPluginPatterns.push({ from: 'src/public', to: 'public' }); - } - - if (target && fs.existsSync(path.resolve(rootDir, 'src/public'))) { - config.plugin('copyWebpackPlugin') - .use(CopyWebpackPlugin, [copyWebpackPluginPatterns]); - } - - return config; -}; diff --git a/packages/build-plugin-rax-app/src/config/kraken/getBase.js b/packages/build-plugin-rax-app/src/config/kraken/getBase.js deleted file mode 100644 index 2373d216f..000000000 --- a/packages/build-plugin-rax-app/src/config/kraken/getBase.js +++ /dev/null @@ -1,13 +0,0 @@ -const getWebpackBase = require('../getWebpackBase'); -const setEntry = require('../setEntry'); -const { KRAKEN } = require('../../constants'); - - -module.exports = (context) => { - const config = getWebpackBase(context, {}, KRAKEN); - setEntry(config, context, KRAKEN); - - config.output.filename(`${KRAKEN}/[name].js`); - - return config; -}; diff --git a/packages/build-plugin-rax-app/src/config/kraken/setDev.js b/packages/build-plugin-rax-app/src/config/kraken/setDev.js deleted file mode 100644 index 3ea0384d1..000000000 --- a/packages/build-plugin-rax-app/src/config/kraken/setDev.js +++ /dev/null @@ -1,16 +0,0 @@ -const { pathHelper: { absoluteModuleResolve } } = require('miniapp-builder-shared'); - -module.exports = (config, context) => { - const { rootDir } = context; - const appEntry = absoluteModuleResolve(rootDir, './src/app'); - const entryConfig = config.entry('index'); - - // Force disable HMR, kraken not support yet. - config.devServer.inline(false); - config.devServer.hot(false); - - // Remove hmr entry. - entryConfig - .clear() - .add(appEntry); -}; diff --git a/packages/build-plugin-rax-app/src/config/miniapp/compile/getBase.js b/packages/build-plugin-rax-app/src/config/miniapp/compile/getBase.js deleted file mode 100644 index 591bd4eea..000000000 --- a/packages/build-plugin-rax-app/src/config/miniapp/compile/getBase.js +++ /dev/null @@ -1,40 +0,0 @@ -const { join } = require('path'); -const { setAppConfig } = require('miniapp-compile-config'); -const { platformMap } = require('miniapp-builder-shared'); - -const getWebpackBase = require('../../getWebpackBase'); - -const { QUICKAPP } = require('../../../constants'); - -module.exports = (context, target, options = {}, onGetWebpackConfig) => { - const entryPath = './src/app'; - const { rootDir, userConfig = {} } = context; - const { outputDir = 'build' } = userConfig; - let outputPath = join(rootDir, outputDir, target); - // Quickapp's output should be wrapped in src - if (target === QUICKAPP) { - outputPath = join(outputPath, 'src'); - } - - const config = getWebpackBase( - context, - { - disableRegenerator: true, - processBar: { - name: platformMap[target].name, - }, - }, - target - ); - - - setAppConfig(config, options[target], { - entryPath, - outputPath, - onGetWebpackConfig, - context, - target - }); - - return config; -}; diff --git a/packages/build-plugin-rax-app/src/config/miniapp/runtime/getBase.js b/packages/build-plugin-rax-app/src/config/miniapp/runtime/getBase.js deleted file mode 100644 index 4c4cc70d0..000000000 --- a/packages/build-plugin-rax-app/src/config/miniapp/runtime/getBase.js +++ /dev/null @@ -1,33 +0,0 @@ -const { setConfig } = require('miniapp-runtime-config'); -const { pathHelper, platformMap } = require('miniapp-builder-shared'); -const { join } = require('path'); - -const getWebpackBase = require('../../getWebpackBase'); -const setEntry = require('../../setEntry'); - -const { getPlatformExtensions } = pathHelper; - -module.exports = (context, target, options, onGetWebpackConfig) => { - const { rootDir } = context; - const config = getWebpackBase(context, { - disableRegenerator: true - }, target); - - setEntry(config, context, target); - onGetWebpackConfig(target, config => { - const { userConfig = {} } = context; - const { outputDir = 'build' } = userConfig; - config.output.path(join(rootDir, outputDir, target)); - config.devServer.contentBase(join(rootDir, outputDir)); - config.resolve.extensions - .clear() - .merge(getPlatformExtensions(platformMap[target].type, ['.js', '.jsx', '.ts', '.tsx', '.json'])); - - setConfig(config, options[target] || {}, { - context, target - }); - }); - - return config; -}; - diff --git a/packages/build-plugin-rax-app/src/config/processRelativePublicPath.js b/packages/build-plugin-rax-app/src/config/processRelativePublicPath.js deleted file mode 100644 index 99c5e5fe8..000000000 --- a/packages/build-plugin-rax-app/src/config/processRelativePublicPath.js +++ /dev/null @@ -1,44 +0,0 @@ -const path = require('path'); - -// Support publicPath use relative path (Called in build script). -module.exports = (target, config) => { - // Change webpack outputPath from 'xx/build' to `xx/build/${target}` - // Change source file's name from `${target}/[name].js` to '[name].js' - // After the above changes, all the asset paths are relative to the entry file (like index.html). - const publicPath = config.output.get('publicPath'); - if (publicPath.startsWith('.')) { - config.output.publicPath(publicPath.endsWith('/') ? publicPath : `${publicPath}/`); - // Update output path and filename - config.output.path(path.resolve(config.output.get('path'), target)); - // `${target}/[name].js` to '[name].js' - config.output.filename(config.output.get('filename').replace(/^[a-zA-Z]+\//, '')); - - // process css file - if (config.plugins.has('minicss')) { - config.plugin('minicss').tap((args) => { - if (args[0].filename) { - // `${target}/[name].css` to '[name].css' - args[0].filename = args[0].filename.replace(/^[a-zA-Z]+\//, ''); - } - return args; - }); - } - - // Update copy public output path, when outputPath is `xx/build/${target}` - // { from: 'src/public', to: 'web/public' } => { from: 'src/public', to: 'public' } - if (config.plugins.get('copyWebpackPlugin')) { - config.plugin('copyWebpackPlugin').tap((args) => args.map((arg) => { - if (Array.isArray(arg)) { - // [{ from: 'xx', to: 'xxx' }] - return arg.map((pattern) => { - if (typeof pattern === 'object' && pattern.to === `${target}/public`) { - return Object.assign(pattern, { to: 'public' }); - } - return pattern; - }); - } - return arg; - })); - } - } -}; \ No newline at end of file diff --git a/packages/build-plugin-rax-app/src/config/setEntry.js b/packages/build-plugin-rax-app/src/config/setEntry.js deleted file mode 100644 index c31665420..000000000 --- a/packages/build-plugin-rax-app/src/config/setEntry.js +++ /dev/null @@ -1,33 +0,0 @@ -const { pathHelper: { absoluteModuleResolve } } = require('miniapp-builder-shared'); - -const { hmrClient } = require('rax-compile-config'); - -const { WECHAT_MINIPROGRAM, MINIAPP, QUICKAPP } = require('../constants'); - - -module.exports = (config, context, target) => { - const { rootDir, command } = context; - const isDev = command === 'start'; - - // SPA - const appEntry = absoluteModuleResolve(rootDir, './src/app'); - const entryConfig = config.entry('index'); - - config.module.rule('appJSON') - .use('loader') - .tap(() => ({ type: target })); - - - ['jsx', 'tsx'].forEach(tag => { - config.module.rule(tag) - .use('platform') - .options({ - platform: target, - }); - }); - - if (isDev && ![WECHAT_MINIPROGRAM, MINIAPP, QUICKAPP].includes(target)) { - entryConfig.add(hmrClient); - } - entryConfig.add(appEntry); -}; diff --git a/packages/build-plugin-rax-app/src/config/user/keys/alias.js b/packages/build-plugin-rax-app/src/config/user/keys/alias.js deleted file mode 100644 index 1686df696..000000000 --- a/packages/build-plugin-rax-app/src/config/user/keys/alias.js +++ /dev/null @@ -1,21 +0,0 @@ -const path = require('path'); -const { existsSync } = require('fs-extra'); - -module.exports = { - defaultValue: {}, - validation: 'object', - configWebpack: (config, value, context) => { - // "alias": { - // "@components": "src/components/", - // "react": "rax" - // } - Object.keys(value).forEach((alias) => { - const fullPath = path.resolve(context.rootDir, value[alias]); - if (existsSync(fullPath)) { - config.resolve.alias.set(alias, fullPath); - } else { - config.resolve.alias.set(alias, value[alias]); - } - }); - }, -}; diff --git a/packages/build-plugin-rax-app/src/config/user/keys/analyzer.js b/packages/build-plugin-rax-app/src/config/user/keys/analyzer.js deleted file mode 100644 index 370ef5a07..000000000 --- a/packages/build-plugin-rax-app/src/config/user/keys/analyzer.js +++ /dev/null @@ -1,13 +0,0 @@ -const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; - -module.exports = { - defaultValue: false, - validation: 'boolean', - configWebpack: (config, value) => { - if (value) { - // reference: https://www.npmjs.com/package/webpack-bundle-analyzer - config.plugin('BundleAnalyzerPlugin') - .use(BundleAnalyzerPlugin); - } - }, -}; diff --git a/packages/build-plugin-rax-app/src/config/user/keys/devPublicPath.js b/packages/build-plugin-rax-app/src/config/user/keys/devPublicPath.js deleted file mode 100644 index da0205fe6..000000000 --- a/packages/build-plugin-rax-app/src/config/user/keys/devPublicPath.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - defaultValue: '/', - validation: 'string', - configWebpack: (config, value, context) => { - const { command } = context; - - if (command === 'start') { - config.output.publicPath(value); - } - }, -}; diff --git a/packages/build-plugin-rax-app/src/config/user/keys/devServer.js b/packages/build-plugin-rax-app/src/config/user/keys/devServer.js deleted file mode 100644 index 70404d797..000000000 --- a/packages/build-plugin-rax-app/src/config/user/keys/devServer.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = { - defaultValue: { - compress: true, - disableHostCheck: true, - clientLogLevel: 'error', - hot: true, - overlay: false, - // Close dev server started message prior. - quiet: false, - noInfo: true, - }, - validation: 'object', - configWebpack: (config, value, context) => { - const { command } = context; - - if (command === 'start') { - config.merge({ devServer: value }); - } - }, -}; diff --git a/packages/build-plugin-rax-app/src/config/user/keys/hash.js b/packages/build-plugin-rax-app/src/config/user/keys/hash.js deleted file mode 100644 index bb14d1f39..000000000 --- a/packages/build-plugin-rax-app/src/config/user/keys/hash.js +++ /dev/null @@ -1,32 +0,0 @@ -const path = require('path'); - -module.exports = { - defaultValue: false, - validation: 'boolean', - configWebpack: (config, value) => { - if (value) { - const hashStr = typeof value === 'boolean' ? 'hash:6' : value; - - const fileName = config.output.get('filename'); - - if (!fileName) { - return; - } - - let pathArray = fileName.split('/'); - pathArray.pop(); - pathArray = pathArray.filter((v) => v); - - const outputPath = pathArray.length ? pathArray.join('/') : ''; - config.output.filename(path.join(outputPath, `[name].[${hashStr}].js`)); - - if (config.plugins.has('minicss')) { - config.plugin('minicss').tap((args) => { - args[0].filename = args[0].filename.replace('[name]', `[name].[${hashStr}]`); - return args; - }); - } - } - }, -}; - diff --git a/packages/build-plugin-rax-app/src/config/user/keys/inlineStyle.js b/packages/build-plugin-rax-app/src/config/user/keys/inlineStyle.js deleted file mode 100644 index 0dcbc6f19..000000000 --- a/packages/build-plugin-rax-app/src/config/user/keys/inlineStyle.js +++ /dev/null @@ -1,161 +0,0 @@ -const { resolve } = require('path'); -const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const { WEB, WEEX, DOCUMENT, KRAKEN, MINIAPP, WECHAT_MINIPROGRAM } = require('../../../constants'); - -const configPath = resolve(__dirname, '../..'); - -const webStandardList = [ - WEB, -]; - -const inlineStandardList = [ - WEEX, KRAKEN, -]; - -const miniappStandardList = [ - MINIAPP, - WECHAT_MINIPROGRAM, -]; - -module.exports = { - defaultValue: true, - validation: 'boolean', - configWebpack: (config, value, context) => { - const { userConfig, taskName } = context; - const { publicPath } = userConfig; - - const cssRule = config.module.rule('css').test(/\.css$/).exclude.add(/\.module\.css$/).end(); - const cssModuleRule = config.module.rule('css-module').test(/\.module\.css$/); - setCSSRule(cssRule, context, value); - setCSSRule(cssModuleRule, context, value, true); - - const lessRule = config.module.rule('less').test(/\.less$/).exclude.add(/\.module\.less$/).end(); - const lessModuleRule = config.module.rule('less-module').test(/\.module\.less$/); - setCSSRule(lessRule, context, value); - setCSSRule(lessModuleRule, context, value, true); - - const sassRule = config.module.rule('sass').test(/\.s[ac]ss$/).exclude.add(/\.module\.s[ac]ss$/).end(); - const sassModuleRule = config.module.rule('sass-module').test(/\.module\.s[ac]ss$/); - setCSSRule(sassRule, context, value); - setCSSRule(sassModuleRule, context, value, true); - - if (inlineStandardList.includes(taskName) || value) { - [lessRule, lessModuleRule].forEach(configRule => { - configRule - .use('less') - .loader(require.resolve('less-loader')); - }); - } else if ((webStandardList.includes(taskName) || miniappStandardList.includes(taskName)) && !value) { - [lessRule, lessModuleRule].forEach(configRule => { - configRule - .oneOf('raw') - .use('less') - .loader(require.resolve('less-loader')) - .end() - .end() - .oneOf('normal') - .use('less') - .loader(require.resolve('less-loader')); - }); - - let filename = `${taskName}/[name].css`; - - if (miniappStandardList.includes(taskName)) { - filename = '[name].css'; - } - - if (publicPath.startsWith('.')) { - filename = ''; - } - - console.log('filename', filename); - - config.plugin('minicss') - .use(MiniCssExtractPlugin, [{ - filename, - ignoreOrder: true - }]); - } - - [sassRule, sassModuleRule].forEach(configRule => { - configRule - .use('sass') - .loader(require.resolve('sass-loader')); - }); - }, -}; - -function setCSSRule(configRule, context, value, isCSSModule) { - const { taskName } = context; - const isInlineStandard = inlineStandardList.includes(taskName); - const isWebStandard = webStandardList.includes(taskName); - const isMiniAppStandard = miniappStandardList.includes(taskName); - const isNodeStandard = taskName === DOCUMENT; - - if (value) { - // enbale inlineStyle - if (isInlineStandard || isMiniAppStandard) { - configInlineStyle(configRule); - } else { - // Only web need transfrom rpx to vw - configInlineStyle(configRule) - .end() - .use('postcss') - .loader(require.resolve('postcss-loader')) - .options({ - config: { - path: configPath, - ctx: { - type: 'inline' - }, - }, - }); - } - } else { - if (isWebStandard || isMiniAppStandard) { - const postcssConfig = { - config: { - path: configPath, - ctx: { - type: isWebStandard ? 'web' : 'miniapp' - }, - }, - }; - const cssLoaderOptions = isCSSModule ? { - modules: { - localIdentName: '[folder]--[local]--[hash:base64:7]', - } - } : {}; - - configRule - .use('minicss') - .loader(MiniCssExtractPlugin.loader) - .end() - .use('css') - .loader(require.resolve('css-loader')) - .options(cssLoaderOptions) - .end() - .use('postcss') - .loader(require.resolve('postcss-loader')) - .options(postcssConfig) - .end(); - } else if (isInlineStandard) { - configInlineStyle(configRule); - } else if (isNodeStandard) { - // Do not generate CSS file, it will be built by web complier - configRule - .use('ignorecss') - .loader(require.resolve('null-loader')) - .end(); - } - } -} - -function configInlineStyle(configRule) { - return configRule - .use('css') - .loader(require.resolve('stylesheet-loader')) - .options({ - transformDescendantCombinator: true, - }); -} diff --git a/packages/build-plugin-rax-app/src/config/user/keys/outputDir.js b/packages/build-plugin-rax-app/src/config/user/keys/outputDir.js deleted file mode 100644 index d4324200b..000000000 --- a/packages/build-plugin-rax-app/src/config/user/keys/outputDir.js +++ /dev/null @@ -1,10 +0,0 @@ -const path = require('path'); - -module.exports = { - defaultValue: 'build', - validation: 'string', - configWebpack: (config, value, context) => { - const { rootDir } = context; - config.output.path(path.resolve(rootDir, value)); - }, -}; diff --git a/packages/build-plugin-rax-app/src/config/user/keys/publicPath.js b/packages/build-plugin-rax-app/src/config/user/keys/publicPath.js deleted file mode 100644 index 82168e544..000000000 --- a/packages/build-plugin-rax-app/src/config/user/keys/publicPath.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - defaultValue: '/', - validation: 'string', - configWebpack: (config, value, context) => { - const { command } = context; - - if (command === 'build') { - config.output.publicPath(value); - } - }, -}; diff --git a/packages/build-plugin-rax-app/src/config/user/keys/sourceMap.js b/packages/build-plugin-rax-app/src/config/user/keys/sourceMap.js deleted file mode 100644 index 39a565a38..000000000 --- a/packages/build-plugin-rax-app/src/config/user/keys/sourceMap.js +++ /dev/null @@ -1,18 +0,0 @@ -const { DOCUMENT } = require('../../../constants'); - -module.exports = { - validation: (val) => { - return typeof val === 'boolean' || typeof val === 'string'; - }, - configWebpack: (config, value, context) => { - const { command, taskName } = context; - // Only valid in build mode and non-document task - if (command === 'build' && taskName !== DOCUMENT) { - if (typeof value === 'boolean') { - value ? config.devtool('source-map') : config.devtool('none'); - } else if (typeof value === 'string') { - config.devtool(value); - } - } - }, -}; diff --git a/packages/build-plugin-rax-app/src/config/user/keys/stats.js b/packages/build-plugin-rax-app/src/config/user/keys/stats.js deleted file mode 100644 index 01e3e13b9..000000000 --- a/packages/build-plugin-rax-app/src/config/user/keys/stats.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - defaultValue: true, - validation: 'boolean', - configWebpack: (config, value, context) => { - const { command } = context; - - // disable webpack stats log - if (command === 'start' && value) { - process.env.DISABLE_STATS = true; - } - }, -}; diff --git a/packages/build-plugin-rax-app/src/config/user/setConfig.js b/packages/build-plugin-rax-app/src/config/user/setConfig.js deleted file mode 100644 index 2d4518f59..000000000 --- a/packages/build-plugin-rax-app/src/config/user/setConfig.js +++ /dev/null @@ -1,16 +0,0 @@ -const path = require('path'); -const klawSync = require('klaw-sync'); - -module.exports = (api) => { - const { registerUserConfig } = api; - const files = klawSync(path.resolve(__dirname, './keys')); - - const configArr = files.map(fileInfo => { - const keyName = path.basename(fileInfo.path).replace('.js', ''); - const keyConfig = require(fileInfo.path); - keyConfig.name = keyName; - return keyConfig; - }); - - registerUserConfig(configArr); -}; diff --git a/packages/build-plugin-rax-app/src/config/web/getBase.js b/packages/build-plugin-rax-app/src/config/web/getBase.js deleted file mode 100644 index cb5266879..000000000 --- a/packages/build-plugin-rax-app/src/config/web/getBase.js +++ /dev/null @@ -1,24 +0,0 @@ -const DocumentPlugin = require('../../plugins/DocumentPlugin/'); -const getWebpackBase = require('../getWebpackBase'); -const setEntry = require('../setEntry'); -const { WEB } = require('../../constants'); - -module.exports = (context, target, options = {}) => { - const config = getWebpackBase(context, {}, WEB); - setEntry(config, context, WEB); - - config.output.filename(`${WEB}/[name].js`); - - config.plugin('document') - .use(DocumentPlugin, [{ - context, - pages: [{ - entryName: 'index', - path: '/' - }], - doctype: options.doctype, - staticExport: options.staticExport - }]); - - return config; -}; diff --git a/packages/build-plugin-rax-app/src/config/weex/getBase.js b/packages/build-plugin-rax-app/src/config/weex/getBase.js deleted file mode 100644 index c385199bc..000000000 --- a/packages/build-plugin-rax-app/src/config/weex/getBase.js +++ /dev/null @@ -1,16 +0,0 @@ -const WeexFrameworkBanner = require('../../plugins/WeexFrameworkBannerPlugin'); -const getWebpackBase = require('../getWebpackBase'); -const setEntry = require('../setEntry'); -const { WEEX } = require('../../constants'); - -module.exports = (context) => { - const config = getWebpackBase(context, {}, WEEX); - setEntry(config, context, WEEX); - - config.output.filename(`${WEEX}/[name].js`); - - config.plugin('weexFrame') - .use(WeexFrameworkBanner); - - return config; -}; diff --git a/packages/build-plugin-rax-app/src/config/weex/setDev.js b/packages/build-plugin-rax-app/src/config/weex/setDev.js deleted file mode 100644 index e005ea182..000000000 --- a/packages/build-plugin-rax-app/src/config/weex/setDev.js +++ /dev/null @@ -1,2 +0,0 @@ -module.exports = () => { -}; diff --git a/packages/build-plugin-rax-app/src/dev.js b/packages/build-plugin-rax-app/src/dev.js deleted file mode 100644 index 8a4c5e9a0..000000000 --- a/packages/build-plugin-rax-app/src/dev.js +++ /dev/null @@ -1,164 +0,0 @@ -const ip = require('ip'); -const chalk = require('chalk'); -const consoleClear = require('console-clear'); -const qrcode = require('qrcode-terminal'); -const { setConfig, setDevLog } = require('rax-multi-pages-settings'); -const { handleWebpackErr } = require('rax-compile-config'); -const checkQuickAppEnv = require('rax-quickapp-webpack-plugin'); -const { resolve } = require('path'); - -const { WEB, WEEX, MINIAPP, KRAKEN, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, QUICKAPP } = require('./constants'); - -module.exports = ({ onGetWebpackConfig, registerTask, context, getValue, onHook }, options = {}) => { - const { targets = [], type = 'spa' } = options; - let devUrl = ''; - let devCompletedArr = []; - - targets.forEach((target, index) => { - const [getBase, setDev] = getConfig(target, options); - registerTask(target, getBase(context, target, options, onGetWebpackConfig)); - - onGetWebpackConfig(target, (config) => { - if (setDev) { - setDev(config, context, index); - } - // Set MPA config - // Should setConfig in onGetWebpackConfig method. Need to get SSR params and all build targets. - if ( - type === 'mpa' - && (target === 'web' || target === 'weex') - ) { - setConfig(config, context, targets, target); - } - }); - }); - - onHook('after.start.compile', async(args) => { - devUrl = args.url; - devCompletedArr.push(args); - devCompileLog(); - }); - - function devCompileLog() { - let err = devCompletedArr[0].err; - let stats = devCompletedArr[0].stats; - - if (!handleWebpackErr(err, stats)) { - return; - } - - // To inform Ali Miniapp IDE to use self watch - if (targets.includes(MINIAPP)) { - console.log('Watching for changes...'); - } - consoleClear(true); - - devCompletedArr.forEach((devInfo) => { - if (devInfo.err || devInfo.stats.hasErrors()) { - err = devInfo.err; - stats = devInfo.stats; - } - }); - - devCompletedArr = []; - - console.log(chalk.green('Rax development server has been started:')); - console.log(); - - // Set Web and Weex log - if (targets.includes(WEB) || targets.includes(WEEX)) { - if ( - type === 'mpa' || - // Compatibility old version build-plugin-rax-multi-pages - getValue('raxMpa') - ) { - setDevLog({ url: devUrl, err, stats }); - } else { - if (targets.includes(WEB)) { - console.log(chalk.green('[Web] Development server at:')); - console.log(' ', chalk.underline.white(devUrl)); - console.log(); - } - - if (targets.includes(WEEX)) { - // Use Weex App to scan ip address (mobile phone can't visit localhost). - const weexUrl = `${devUrl}weex/index.js?wh_weex=true`.replace(/^http:\/\/localhost/gi, function(match) { - // Called when matched - try { - return `http://${ip.address()}`; - } catch (error) { - console.log(chalk.yellow(`Get local IP address failed: ${error.toString()}`)); - return match; - } - }); - console.log(chalk.green('[Weex] Development server at:')); - console.log(' ', chalk.underline.white(weexUrl)); - console.log(); - qrcode.generate(weexUrl, { small: true }); - console.log(); - } - } - } - - if (targets.includes(KRAKEN)) { - const krakenURL = `${devUrl}kraken/index.js`; - console.log(chalk.green('[Kraken] Development server at:')); - console.log(' ', chalk.underline.white(krakenURL)); - console.log(chalk.green('[Kraken] Run Kraken Playground App:')); - console.log(' ', chalk.underline.white(`kraken -u ${krakenURL}`)); - console.log(); - } - - if (targets.includes(MINIAPP)) { - console.log(chalk.green('[Ali Miniapp] Use ali miniapp developer tools to open the following folder:')); - console.log(' ', chalk.underline.white(getOutputPath(context, MINIAPP))); - console.log(); - } - - if (targets.includes(WECHAT_MINIPROGRAM)) { - console.log(chalk.green('[WeChat MiniProgram] Use wechat miniprogram developer tools to open the following folder:')); - console.log(' ', chalk.underline.white(getOutputPath(context, WECHAT_MINIPROGRAM))); - console.log(); - } - - if (targets.includes(BYTEDANCE_MICROAPP)) { - console.log(chalk.green('[ByteDance MicroApp] Use bytedance microapp developer tools to open the following folder:')); - console.log(' ', chalk.underline.white(getOutputPath(context, BYTEDANCE_MICROAPP))); - console.log(); - } - - if (targets.includes(QUICKAPP)) { - // Check for quick app's environment - const quickAppDist = getOutputPath(context, QUICKAPP); - checkQuickAppEnv({ - workDirectory: process.cwd(), - distDirectory: quickAppDist, - }); - console.log(chalk.green('[Quick App] Use quick app developer tools to open the following folder:')); - console.log(' ', chalk.underline.white(quickAppDist)); - console.log(); - } - } -}; - -function getConfig(target, options = {}) { - if ([MINIAPP, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, QUICKAPP].indexOf(target) > -1) { - if (options[target] && options[target].buildType === 'runtime') { - return [require('./config/miniapp/runtime/getBase')]; - } else { - if (options[target]) { - options[target].mode = 'watch'; - } else { - options[target] = { mode: 'watch' }; - } - return [require('./config/miniapp/compile/getBase')]; - } - } - return [require(`./config/${target}/getBase`), require(`./config/${target}/setDev`)]; -} - -function getOutputPath(context, target) { - const { rootDir, userConfig } = context; - const { outputDir = 'build' } = userConfig; - return resolve(rootDir, outputDir, target); -} diff --git a/packages/build-plugin-rax-app/src/index.js b/packages/build-plugin-rax-app/src/index.js deleted file mode 100644 index 0fb207eb0..000000000 --- a/packages/build-plugin-rax-app/src/index.js +++ /dev/null @@ -1,57 +0,0 @@ -const chalk = require('chalk'); -const setUserConfig = require('./config/user/setConfig'); - -const build = require('./build'); -const dev = require('./dev'); - -const pluginApp = (api, options = {}) => { - if (typeof options.enterCheck === 'boolean' ? options.enterCheck : true) { - enterCheck(api, options); - } - - api.setValue('targets', options.targets); - api.setValue('appType', options.type || 'spa'); - - const { context } = api; - const { command } = context; - - setUserConfig(api, options); - - if (command === 'build') { - build(api, options); - } - - if (command === 'start') { - dev(api, options); - } -}; - -function enterCheck(api, options) { - const { context, log } = api; - const { plugins } = context.userConfig; - - let errMsg = ''; - let hasError = false; - - const firstPluginName = Array.isArray(plugins[0]) ? plugins[0][0] : plugins[0]; - - if (!/build-plugin-rax-app/.test(firstPluginName)) { - errMsg = 'build-plugin-rax-app must be the first plugin, please check the order of plugins'; - hasError = true; - } - - if (!(options.targets && options.targets.length)) { - errMsg = 'build-plugin-rax-app need to set targets, e.g. ["build-plugin-rax-app", targets: ["web", "weex"]]'; - hasError = true; - } - - if (hasError) { - log.error(chalk.red(errMsg)); - console.log(); - process.exit(1); - } -} - -pluginApp.getWebBase = require('./config/web/getBase'); - -module.exports = pluginApp; diff --git a/packages/build-plugin-rax-app/src/loaders/AppConfigLoader/getDepPath.js b/packages/build-plugin-rax-app/src/loaders/AppConfigLoader/getDepPath.js deleted file mode 100644 index cf219a7a3..000000000 --- a/packages/build-plugin-rax-app/src/loaders/AppConfigLoader/getDepPath.js +++ /dev/null @@ -1,17 +0,0 @@ -const { join } = require('path'); -const { existsSync } = require('fs-extra'); - -/** - * ./pages/foo -> based on src, return original - * /pages/foo -> based on rootContext - * pages/foo -> based on src, add prefix: './' - */ -module.exports = function getDepPath(path, rootContext = '') { - if (path[0] === '.') { - return path; - } else if (path[0] === '/') { - return join(rootContext, path); - } else { - return `./${path}`; - } -}; diff --git a/packages/build-plugin-rax-app/src/loaders/AppConfigLoader/index.js b/packages/build-plugin-rax-app/src/loaders/AppConfigLoader/index.js deleted file mode 100644 index 2e21a1558..000000000 --- a/packages/build-plugin-rax-app/src/loaders/AppConfigLoader/index.js +++ /dev/null @@ -1,102 +0,0 @@ -const { getRouteName } = require('rax-compile-config'); -const { getOptions } = require('loader-utils'); -const getDepPath = require('./getDepPath'); - -/** - * universal-app-config-loader - * return { - * "routes": [ - { - "path": "/", - "source": "pages/Home/index", - "component": fn, - } - ], - "shell": { - "source": "shell/index", - "component": fn - }, - "hydrate": false - } - */ -module.exports = function(appJSON) { - const options = getOptions(this) || {}; - const { type } = options; - const appConfig = JSON.parse(appJSON); - - if (!appConfig.routes || !Array.isArray(appConfig.routes)) { - throw new Error('routes should be an array in app.json.'); - } - - appConfig.routes = appConfig.routes.filter(route => { - if (Array.isArray(route.targets) && !route.targets.includes(type)) { - return false; - } - - return true; - }); - - const assembleRoutes = appConfig.routes.map((route) => { - if (!route.path || !route.source) { - throw new Error('route object should have path and source.'); - } - - // Set page title: Web use document.title; Weex need Native App support title api; - // Default route title: appConfig.window.title - let routeTitle = appConfig.window && appConfig.window.title ? appConfig.window.title : ''; - if (route.window && route.window.title) { - // Current route title: route.window.title - routeTitle = route.window.title; - } - - // First level function to support hooks will autorun function type state, - // Second level function to support rax-use-router rule autorun function type component. - const dynamicImportComponent = - `(routeProps) => - import(/* webpackChunkName: "${getRouteName(route, this.rootContext).toLocaleLowerCase()}.chunk" */ '${getDepPath(route.source, this.rootContext)}') - .then((mod) => () => { - const reference = interopRequire(mod); - function Component(props) { - return createElement(reference, Object.assign({}, routeProps, props)); - } - ${routeTitle ? `document.title="${routeTitle}"` : ''} - Component.__path = '${route.path}'; - return Component; - }) - `; - const importComponent = `() => () => interopRequire(require('${getDepPath(route.source, this.rootContext)}'))`; - - return `routes.push( - { - ...${JSON.stringify(route)}, - component: ${type === 'web' ? dynamicImportComponent : importComponent} - } - );`; - }).join('\n'); - - let processShell; - if (appConfig.shell) { - processShell = ` - import Shell from "${getDepPath(appConfig.shell.source, this.rootContext)}"; - appConfig.shell = { - source: '${appConfig.shell.source}', - component: Shell - }; - `; - } else { - processShell = ''; - } - - return ` - import { createElement } from 'rax'; - const interopRequire = (mod) => mod && mod.__esModule ? mod.default : mod; - const routes = []; - ${assembleRoutes} - const appConfig = { - ...${appJSON}, - routes - }; - ${processShell} - export default appConfig; - `; -}; diff --git a/packages/build-plugin-rax-app/src/plugins/DocumentPlugin/config.js b/packages/build-plugin-rax-app/src/plugins/DocumentPlugin/config.js deleted file mode 100644 index a03b1cd48..000000000 --- a/packages/build-plugin-rax-app/src/plugins/DocumentPlugin/config.js +++ /dev/null @@ -1,52 +0,0 @@ -const path = require('path'); -const klawSync = require('klaw-sync'); -const getWebpackBase = require('rax-webpack-config'); -const getBabelConfig = require('rax-babel-config'); - -const babelConfig = getBabelConfig({ - styleSheet: true, - isNode: true -}); - -/** - * webpack config for document - */ -module.exports = (context, options) => { - const { userConfig, rootDir, command } = context; - const { alias = {}, configWebpack } = options; - - const config = getWebpackBase({ - rootDir, - command, - babelConfig, - }); - - config.target('node'); - - config.output - .libraryTarget('commonjs2'); - - // Sync the alias from webpack config for Web. eg. react, react-dom - Object.keys(alias).forEach((key) => { - config.resolve.alias.set(key, alias[key]); - }); - - // Sync the user config in build.json to document config. - const files = klawSync(path.resolve(__dirname, '../../config/user/keys')); - files.map(fileInfo => { - const userConfigKey = path.basename(fileInfo.path).replace('.js', ''); - const userConfigRegister = require(fileInfo.path); - const value = userConfig.hasOwnProperty(userConfigKey) ? userConfig[userConfigKey] : userConfigRegister.defaultValue; - userConfigRegister.configWebpack(config, value, { - ...context, - taskName: 'document', - }); - }); - - // Sync the custom config for document. - if (configWebpack) { - configWebpack(config); - } - - return config; -}; diff --git a/packages/build-plugin-rax-block/README.md b/packages/build-plugin-rax-block/README.md deleted file mode 100644 index 10b06ac87..000000000 --- a/packages/build-plugin-rax-block/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# build-plugin-rax-block - -plugin for rax block development - -## Usage - -```json -{ - "plugins": [ - "build-plugin-rax-block" - ] -} -``` - diff --git a/packages/build-plugin-rax-block/package.json b/packages/build-plugin-rax-block/package.json deleted file mode 100644 index 372a5caed..000000000 --- a/packages/build-plugin-rax-block/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "build-plugin-rax-block", - "version": "0.1.1", - "description": "plugin for rax block development", - "main": "src/index.js", - "keywords": [ - "build-scripts", - "rax", - "block" - ], - "dependencies": { - "build-plugin-rax-component": "^0.2.0", - "html-webpack-plugin": "^4.3.0" - } -} diff --git a/packages/build-plugin-rax-block/src/index.js b/packages/build-plugin-rax-block/src/index.js deleted file mode 100644 index 83b38ce42..000000000 --- a/packages/build-plugin-rax-block/src/index.js +++ /dev/null @@ -1,31 +0,0 @@ -const fs = require('fs'); -const path = require('path'); -const buildComponent = require('build-plugin-rax-component'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); - -// Treat rax iceworks block as rax component. -module.exports = (api, options = {}) => { - const { onGetWebpackConfig, context } = api; - const { command, rootDir } = context; - - // Use ice and rax 'demo/index' file as preview entry. - const demoDir = path.resolve(rootDir, 'demo'); - - if ( - !fs.existsSync(demoDir) || - !fs.readdirSync(demoDir).find(file => file.indexOf('index') > -1) - ) { - throw new Error('Rax block template need "demo/index" file to debug your block.'); - } - - buildComponent(api, options); - - // Add build/index.html output - if (command === 'build') { - onGetWebpackConfig('component-build-web', (config) => { - config.entry('index').clear().add(path.resolve(demoDir, 'index')); - config.plugin('html').use(HtmlWebpackPlugin); - config.externals([]); - }); - } -}; diff --git a/packages/build-plugin-rax-component/README.md b/packages/build-plugin-rax-component/README.md deleted file mode 100644 index f3bda3126..000000000 --- a/packages/build-plugin-rax-component/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# build-plugin-rax-component [![npm](https://img.shields.io/npm/v/rax-plugin-component.svg)](https://www.npmjs.com/package/build-plugin-rax-component) - -`build-scripts` plugin which contains base configuration of rax universal component - -## Usage - -```json -{ - "plugins": [ - "build-plugin-rax-component" - ] -} -``` diff --git a/packages/build-plugin-rax-component/package.json b/packages/build-plugin-rax-component/package.json deleted file mode 100644 index fc1dbbc1f..000000000 --- a/packages/build-plugin-rax-component/package.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "name": "build-plugin-rax-component", - "version": "0.2.15", - "description": "rax component base plugins", - "license": "BSD-3-Clause", - "main": "src/index.js", - "repository": { - "type": "git" - }, - "peerDependencies": { - "rax": "^1.0.0" - }, - "dependencies": { - "babel-loader": "8.0.4", - "case-sensitive-paths-webpack-plugin": "^2.1.2", - "chalk": "^2.4.2", - "chokidar": "^3.3.1", - "console-clear": "^1.1.1", - "css-loader": "^2.1.1", - "deepmerge": "^4.0.0", - "error-stack-tracey": "^0.1.0", - "fs-extra": "^8.1.0", - "glob": "^7.1.6", - "gulp": "^4.0.2", - "gulp-babel": "^8.0.0", - "gulp-cli": "^2.2.0", - "gulp-typescript": "^5.0.1", - "html-webpack-plugin": "^3.2.0", - "image-source-loader": "^0.6.5", - "ip": "^1.1.5", - "jsx2mp-runtime": "^0.4.7", - "klaw-sync": "^6.0.0", - "less": "^3.9.0", - "less-loader": "^5.0.0", - "loader-utils": "^1.1.0", - "lodash": "^4.17.15", - "memory-fs": "^0.5.0", - "mini-css-extract-plugin": "^0.8.0", - "miniapp-builder-shared": "^0.1.2", - "miniapp-compile-config": "^0.1.0", - "optimize-css-assets-webpack-plugin": "^5.0.3", - "postcss": "^7.0.17", - "postcss-loader": "^3.0.0", - "postcss-plugin-rpx2vw": "^0.0.1", - "postcss-preset-env": "^6.6.0", - "qrcode-terminal": "^0.12.0", - "rax-babel-config": "^0.1.0", - "rax-compile-config": "^0.2.0", - "remark": "^11.0.2", - "shelljs": "^0.8.3", - "stylesheet-loader": "^0.8.0", - "terser": "^4.6.7", - "terser-webpack-plugin": "^2.1.3", - "ts-loader": "^6.0.4", - "typescript": "^3.5.3", - "webpack": "^4.27.1", - "webpack-chain": "^6.0.0", - "webpack-node-externals": "^1.7.2", - "webpack-sources": "^1.4.3" - } -} diff --git a/packages/build-plugin-rax-component/src/build.js b/packages/build-plugin-rax-component/src/build.js deleted file mode 100644 index 93fb4b7ed..000000000 --- a/packages/build-plugin-rax-component/src/build.js +++ /dev/null @@ -1,108 +0,0 @@ -const fse = require('fs-extra'); -const path = require('path'); -const chalk = require('chalk'); -const consoleClear = require('console-clear'); -const { handleWebpackErr } = require('rax-compile-config'); -const { platformMap } = require('miniapp-builder-shared'); - -const getDistConfig = require('./config/getDistConfig'); -const getUMDConfig = require('./config/getUMDConfig'); -const getES6Config = require('./config/getES6Config'); -const getMiniappConfig = require('./config/miniapp/getBase'); -const gulpCompile = require('./gulp/compile'); -const gulpParams = require('./gulp/params'); - -const { WEB, WEEX, MINIAPP, WECHAT_MINIPROGRAM } = require('./constants'); - -module.exports = (api, options = {}) => { - const { registerTask, modifyUserConfig, context, onHook, onGetWebpackConfig, log } = api; - const { targets = [] } = options; - const { rootDir } = context; - const libDir = 'lib'; - const distDir = 'dist'; - - // omitLib just for sfc2mp,not for developer - const disableGenerateLib = options[MINIAPP] && options[MINIAPP].omitLib; - - // clean build results - fse.removeSync(path.join(rootDir, libDir)); - fse.removeSync(path.join(rootDir, distDir)); - fse.removeSync(path.join(rootDir, 'build')); - fse.removeSync(path.join(rootDir, 'es')); - - targets.forEach(target => { - if (target === WEEX || target === WEB) { - const config = getDistConfig(context, options); - const umdConfig = getUMDConfig(context, options); - const es6Config = getES6Config(context, options); - // compress and minify all files - modifyUserConfig('outputDir', distDir); - registerTask(`component-build-${target}`, config); - registerTask(`component-build-${target}-umd`, umdConfig); - registerTask(`component-build-${target}-es6`, es6Config); - } - if (target === MINIAPP || target === WECHAT_MINIPROGRAM) { - options[target] = options[target] || {}; - addMiniappTargetParam(target, options[target]); - const config = getMiniappConfig(context, target, options, onGetWebpackConfig); - registerTask(`component-build-${target}`, config); - } - }); - - onHook('before.build.load', async() => { - consoleClear(true); - - if (!disableGenerateLib) { - // start build lib&es by babel - log.info('component', chalk.green('Build start... ')); - - // set gulpParams - gulpParams.api = api; - gulpParams.options = options; - - gulpCompile(); - } - }); - - onHook('after.build.compile', async({ err, stats }) => { - consoleClear(true); - - if (!handleWebpackErr(err, stats)) { - return; - } - - console.log(chalk.green('Rax Component build finished:')); - console.log(); - - if (targets.includes(WEB) || targets.includes(WEEX)) { - console.log(chalk.green('Component lib at:')); - console.log(' ', chalk.underline.white(path.resolve(rootDir, libDir))); - console.log(); - - console.log(chalk.green('Component dist at:')); - console.log(' ', chalk.underline.white(path.resolve(rootDir, distDir))); - console.log(); - } - Object.entries(platformMap).forEach(([platform, config]) => { - if (targets.includes(platform)) { - console.log(chalk.green(`[${config.name}] Component lib at:`)); - const distDir = options[platform].distDir || `${libDir}/${platform}`; - console.log(' ', chalk.underline.white(path.resolve(rootDir, distDir))); - console.log(); - } - }); - }); -}; - -/** - * Add miniapp target param to match jsx2mp-loader config - * */ -function addMiniappTargetParam(target, originalConfig = {}) { - switch (target) { - case WECHAT_MINIPROGRAM: - originalConfig.platform = 'wechat'; - break; - default: - break; - } -} diff --git a/packages/build-plugin-rax-component/src/config/demo.html b/packages/build-plugin-rax-component/src/config/demo.html deleted file mode 100644 index 905a2b7cb..000000000 --- a/packages/build-plugin-rax-component/src/config/demo.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - Rax Component Demo - - -
- - diff --git a/packages/build-plugin-rax-component/src/config/getBaseWebpack.js b/packages/build-plugin-rax-component/src/config/getBaseWebpack.js deleted file mode 100644 index 4992f7a57..000000000 --- a/packages/build-plugin-rax-component/src/config/getBaseWebpack.js +++ /dev/null @@ -1,110 +0,0 @@ -const webpack = require('webpack'); -const path = require('path'); -const Chain = require('webpack-chain'); -const { setBabelAlias } = require('rax-compile-config'); -const getBabelConfig = require('rax-babel-config'); -const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); -const TerserPlugin = require('terser-webpack-plugin'); -const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); - - -module.exports = (context, options) => { - const { rootDir, command, pkg } = context; - const { isES6 } = options || {}; - const config = new Chain(); - - const babelConfig = getBabelConfig({ - styleSheet: true, - isES6, - custom: { - ignore: ['**/**/*.d.ts'], - }, - }); - - setBabelAlias(config); - - config.target('web'); - config.context(rootDir); - - config.externals([ - function(ctx, request, callback) { - if (request.indexOf('@weex-module') !== -1) { - return callback(null, `commonjs ${request}`); - } - // Built-in modules in QuickApp - if (request.indexOf('@system') !== -1) { - return callback(null, `commonjs ${request}`); - } - callback(); - }, - ]); - - config.resolve.extensions.merge(['.js', '.json', '.jsx', '.ts', '.tsx', '.html']); - - config.module - .rule('jsx') - .test(/\.(js|mjs|jsx)$/) - .use('babel') - .loader(require.resolve('babel-loader')) - .options(babelConfig); - - config.module - .rule('tsx') - .test(/\.tsx?$/) - .use('babel') - .loader(require.resolve('babel-loader')) - .options(babelConfig) - .end() - .use('ts') - .loader(require.resolve('ts-loader')); - - config.module - .rule('md') - .test(/\.md$/) - .use('babel') - .loader(require.resolve('babel-loader')) - .options(babelConfig) - .end() - .use('markdown-loader') - .loader(require.resolve('../loaders/MarkdownLoader/index')); - - config.module - .rule('assets') - .test(/\.(svg|png|webp|jpe?g|gif)$/i) - .use('source') - .loader(require.resolve('image-source-loader')); - - config.plugin('caseSensitivePaths').use(CaseSensitivePathsPlugin); - - config.plugin('noError').use(webpack.NoEmitOnErrorsPlugin); - - if (command === 'start') { - config.mode('development'); - config.devtool('inline-module-source-map'); - } else if (command === 'build') { - config.mode('production'); - - config.optimization - .minimizer('terser') - .use(TerserPlugin, [ - { - terserOptions: { - output: { - ascii_only: true, - comments: false, - }, - }, - extractComments: false, - }, - ]) - .end() - .minimizer('optimizeCSS') - .use(OptimizeCSSAssetsPlugin); - } - - if (pkg.name) { - config.resolve.alias.set(pkg.name, path.resolve(rootDir, 'src/index')); - } - - return config; -}; diff --git a/packages/build-plugin-rax-component/src/config/getDemos.js b/packages/build-plugin-rax-component/src/config/getDemos.js deleted file mode 100644 index 773a0d635..000000000 --- a/packages/build-plugin-rax-component/src/config/getDemos.js +++ /dev/null @@ -1,58 +0,0 @@ -const path = require('path'); -const glob = require('glob'); -const fs = require('fs'); - -module.exports = function(rootDir, options = {}) { - const demos = []; - const isNode = options.type === 'node'; - - // Compatible with original way - // ├── demo - // | ├── index.jsx - if (!isNode) { - // read demos - glob.sync(path.resolve(rootDir, 'demo/*.{js,jsx,md}')).forEach(filePath => { - const name = filePath.substring( - filePath.lastIndexOf('/') + 1, - Math.max(filePath.indexOf('.js'), filePath.indexOf('.md')), - ); - - demos.push({ - name, - filePath, - }); - }); - } - - const demoDir = path.resolve(rootDir, 'demo'); - const folders = fs.readdirSync(demoDir).filter(f => fs.statSync(path.join(demoDir, f)).isDirectory()); - - // ├── demo - // | ├── index - // | | ├── index.client.jsx - // | | ├── index.server.jsx - const platform = isNode ? 'server' : 'client'; - folders.forEach((folder) => { - let platformEntry; - - glob.sync(path.resolve(demoDir, `${folder}/index.${platform}.{js,jsx}`)).forEach(filePath => { - platformEntry = filePath; - }); - - // If index.{platform}.{js,jsx} are not found, use index.{js,jsx} - if (!platformEntry) { - glob.sync(path.resolve(demoDir, `${folder}/index.{js,jsx}`)).forEach(filePath => { - platformEntry = filePath; - }); - } - - if (platformEntry) { - demos.push({ - name: folder, - filePath: platformEntry, - }); - } - }); - - return demos; -}; diff --git a/packages/build-plugin-rax-component/src/config/getDistConfig.js b/packages/build-plugin-rax-component/src/config/getDistConfig.js deleted file mode 100644 index 60ffe9ddc..000000000 --- a/packages/build-plugin-rax-component/src/config/getDistConfig.js +++ /dev/null @@ -1,103 +0,0 @@ -const path = require('path'); -const nodeExternals = require('webpack-node-externals'); -const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const getBaseWebpack = require('./getBaseWebpack'); - -module.exports = (context, options) => { - const config = getBaseWebpack(context, options); - - const { rootDir, taskName } = context; - - config.target('web'); - - config.entry('index') - .add(path.resolve(rootDir, 'src/index')); - - - config.externals([ - function(ctx, request, callback) { - if (request.indexOf('@weex-module') !== -1) { - return callback(null, `commonjs ${request}`); - } - // Built-in modules in QuickApp - if (request.indexOf('@system') !== -1) { - return callback(null, `commonjs ${request}`); - } - callback(); - }, - nodeExternals(), - ]); - - if (options.forceInline) { - config.module.rule('css') - .test(/\.css?$/) - .use('css') - .loader(require.resolve('stylesheet-loader')) - .options({ taskName }); - - config.module.rule('less') - .test(/\.less?$/) - .use('css') - .loader(require.resolve('stylesheet-loader')) - .options({ taskName }) - .end() - .use('less') - .loader(require.resolve('less-loader')); - } else { - config.module.rule('css') - .test(/\.css?$/) - .use('minicss') - .loader(MiniCssExtractPlugin.loader) - .end() - .use('css') - .loader(require.resolve('css-loader')) - .end() - .use('postcss') - .loader(require.resolve('postcss-loader')) - .options({ - ident: 'postcss', - plugins: () => [ - require('postcss-preset-env')({ - autoprefixer: { - flexbox: 'no-2009', - }, - stage: 3, - }), - require('postcss-plugin-rpx2vw')(), - ], - }); - - config.module.rule('less') - .test(/\.less?$/) - .use('minicss') - .loader(MiniCssExtractPlugin.loader) - .end() - .use('css') - .loader(require.resolve('css-loader')) - .end() - .use('postcss') - .loader(require.resolve('postcss-loader')) - .options({ - ident: 'postcss', - plugins: () => [ - require('postcss-preset-env')({ - autoprefixer: { - flexbox: 'no-2009', - }, - stage: 3, - }), - require('postcss-plugin-rpx2vw')(), - ], - }) - .end() - .use('less') - .loader(require.resolve('less-loader')); - } - - config.plugin('minicss') - .use(MiniCssExtractPlugin, [{ - filename: '[name].css', - }]); - - return config; -}; diff --git a/packages/build-plugin-rax-component/src/config/getES6Config.js b/packages/build-plugin-rax-component/src/config/getES6Config.js deleted file mode 100644 index f7aa22b8f..000000000 --- a/packages/build-plugin-rax-component/src/config/getES6Config.js +++ /dev/null @@ -1,8 +0,0 @@ -const getDistConfig = require('./getDistConfig'); -const _ = require('lodash'); - -module.exports = (context, options) => { - const config = getDistConfig(context, {...options, isES6: true}); - config.output.filename('index-es6.js'); - return config; -}; diff --git a/packages/build-plugin-rax-component/src/config/getUMDConfig.js b/packages/build-plugin-rax-component/src/config/getUMDConfig.js deleted file mode 100644 index 2f5d2ede7..000000000 --- a/packages/build-plugin-rax-component/src/config/getUMDConfig.js +++ /dev/null @@ -1,14 +0,0 @@ -const getDistConfig = require('./getDistConfig'); -const _ = require('lodash'); - -module.exports = (context, options) => { - const config = getDistConfig(context, options); - const {pkg} = context; - const pkgName = _.camelCase(pkg.name || ''); - - config.output.library(pkgName); - config.output.libraryTarget('umd'); - config.output.filename('index.umd.js'); - - return config; -}; diff --git a/packages/build-plugin-rax-component/src/config/miniapp/getBase.js b/packages/build-plugin-rax-component/src/config/miniapp/getBase.js deleted file mode 100644 index 8fe81f06a..000000000 --- a/packages/build-plugin-rax-component/src/config/miniapp/getBase.js +++ /dev/null @@ -1,22 +0,0 @@ -const { setComponentConfig } = require('miniapp-compile-config'); - -const getWebpackBase = require('../getBaseWebpack'); -const getOutputPath = require('./getOutputPath'); - -module.exports = (context, target, options = {}, onGetWebpackConfig) => { - const { entryPath = './src/index', distDir = '' } = options[target] || {}; - const outputPath = getOutputPath(context, { target, distDir }); - const config = getWebpackBase(context, { - disableRegenerator: true - }); - - setComponentConfig(config, options[target], { - onGetWebpackConfig, - context, - entryPath, - outputPath, - target - }); - - return config; -}; diff --git a/packages/build-plugin-rax-component/src/config/miniapp/getOutputPath.js b/packages/build-plugin-rax-component/src/config/miniapp/getOutputPath.js deleted file mode 100644 index 02d1a8f25..000000000 --- a/packages/build-plugin-rax-component/src/config/miniapp/getOutputPath.js +++ /dev/null @@ -1,17 +0,0 @@ -const { resolve } = require('path'); -const { MINIAPP } = require('../../constants'); - -module.exports = (context, { target = MINIAPP, distDir = '' }) => { - const { rootDir, command, userConfig } = context; - if (distDir) { - return resolve(rootDir, distDir); - } - - const { outputDir = 'lib' } = userConfig; - - if (command === 'build') { - return resolve(rootDir, outputDir, target); - } else { - return resolve(rootDir, 'demo', target, 'components', 'Target'); - } -}; diff --git a/packages/build-plugin-rax-component/src/config/node/getDev.js b/packages/build-plugin-rax-component/src/config/node/getDev.js deleted file mode 100644 index 39e686431..000000000 --- a/packages/build-plugin-rax-component/src/config/node/getDev.js +++ /dev/null @@ -1,119 +0,0 @@ -const path = require('path'); -const Module = require('module'); -const { parse, print } = require('error-stack-tracey'); - -const getBaseWebpack = require('../getBaseWebpack'); -const getDemos = require('../getDemos'); - -function exec(code, filename, filePath) { - const module = new Module(filename, this); - module.paths = Module._nodeModulePaths(filePath); - module.filename = filename; - module._compile(code, filename); - return module.exports; -} - -module.exports = (context, options) => { - const config = getBaseWebpack(context); - const { rootDir } = context; - - const demos = getDemos(rootDir, { - type: 'node', - }); - - demos.forEach(({ name, filePath }) => { - config - .entry(name) - .add(filePath); - }); - - config.target('node'); - - config.output - .path(rootDir) - .libraryTarget('commonjs2'); - - config.output.filename('ssr/[name].js'); - - if (options.forceInline) { - config.module - .rule('css') - .test(/\.css?$/) - .use('css') - .loader(require.resolve('stylesheet-loader')); - - config.module - .rule('less') - .test(/\.less?$/) - .use('css') - .loader(require.resolve('stylesheet-loader')) - .end() - .use('less') - .loader(require.resolve('less-loader')); - } else { - config.plugins.delete('minicss'); - - config.module.rules.delete('css'); - config.module.rule('css') - .test(/\.css?$/) - .use('ignorecss') - .loader(require.resolve('./ignoreLoader')) - .end(); - - config.module.rules.delete('less'); - config.module.rule('less') - .test(/\.less?$/) - .use('ignorecss') - .loader(require.resolve('./ignoreLoader')) - .end(); - } - - config.devServer.set('before', (app, devServer) => { - const outputFs = devServer.compiler.compilers[0].outputFileSystem; - - demos.forEach((demo) => { - app.get(`/ssr/${demo.name}`, async function(req, res) { - const query = req.query || {}; - // disable hydarte for debug http://localhost:9999/ssr/index?hydrate=false - const hydrate = query.hydrate !== 'false'; - - const bundleContent = outputFs.readFileSync(path.join(rootDir, `ssr/${demo.name}.js`), 'utf8'); - - let content; - - try { - const mod = exec(bundleContent, demo.filePath, demo.filePath); - content = mod.default(); - } catch (error) { - const errorStack = await parse(error, bundleContent); - print(error.message, errorStack); - - const stackMessage = errorStack.map(frame => frame.source); - content = `Error: ${error.message}
${stackMessage.join('
')}`; - } - - const existsCSS = outputFs.existsSync(path.join(rootDir, `dist/${demo.name}.css`)); - const style = existsCSS ? `` : ''; - const srcipt = hydrate ? `` : ''; - - const html = ` - - - - - - Rax Component Demo - ${style} - - -
${content}
- ${srcipt} - - `; - res.send(html); - }); - }); - }); - - return config; -}; diff --git a/packages/build-plugin-rax-component/src/config/node/ignoreLoader.js b/packages/build-plugin-rax-component/src/config/node/ignoreLoader.js deleted file mode 100644 index d33e1f50c..000000000 --- a/packages/build-plugin-rax-component/src/config/node/ignoreLoader.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = function() { - this.cacheable && this.cacheable(); - return ''; -}; diff --git a/packages/build-plugin-rax-component/src/config/parseMarkdown.js b/packages/build-plugin-rax-component/src/config/parseMarkdown.js deleted file mode 100644 index e680b6ffa..000000000 --- a/packages/build-plugin-rax-component/src/config/parseMarkdown.js +++ /dev/null @@ -1,63 +0,0 @@ -const remarkAbstract = require('remark'); -const colors = require('chalk'); -const fs = require('fs-extra'); - -const remark = remarkAbstract(); - -/** - * Parse demo markdown - * @param name - * @param content - * @param filePath - * @returns { Object } result { meta: {name, order, title, desc } } - */ -module.exports = (name, content, filePath) => { - const result = { - meta: { - name, - }, - js: null, - css: null, - html: null, - }; - - if (!content) { - content = fs.readFileSync(filePath).toString(); - } - - if (!content) return result; - - const AST = remark.parse(content); - - if (!AST || !AST.children) { - colors.yellow(`Can not parse the demo markdown file at: ${filePath}`); - return result; - } - - // code - const body = AST.children; - - const jsNode = body.find( - child => - child.type === 'code' && (child.lang === 'js' || child.lang === 'jsx'), - ); - if (jsNode) { - result.js = jsNode.value; - } - - const cssNode = body.find( - child => child.type === 'code' && child.lang === 'css', - ); - if (cssNode) { - result.css = cssNode.value; - } - - const htmlNode = body.find( - child => child.type === 'code' && child.lang === 'html', - ); - if (htmlNode) { - result.html = htmlNode.value; - } - - return result; -}; diff --git a/packages/build-plugin-rax-component/src/config/user/default.config.js b/packages/build-plugin-rax-component/src/config/user/default.config.js deleted file mode 100644 index 8e019d3ca..000000000 --- a/packages/build-plugin-rax-component/src/config/user/default.config.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = { - outputDir: 'lib', - devOutputDir: 'lib', - devWatchLib: false, - distDir: 'build', - publicPath: '/', - devPublicPath: '/', - devServer: { - compress: true, - disableHostCheck: true, - clientLogLevel: 'error', - hot: true, - quiet: true, - overlay: false, - }, -}; diff --git a/packages/build-plugin-rax-component/src/config/user/keys/devPublicPath.js b/packages/build-plugin-rax-component/src/config/user/keys/devPublicPath.js deleted file mode 100644 index 133f5db1c..000000000 --- a/packages/build-plugin-rax-component/src/config/user/keys/devPublicPath.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - defaultValue: '/', - validation: 'string', - configWebpack: (config, value, context) => { - const { command } = context; - - if (command === 'start') { - config.output.publicPath(value); - } - }, -}; \ No newline at end of file diff --git a/packages/build-plugin-rax-component/src/config/user/keys/devServer.js b/packages/build-plugin-rax-component/src/config/user/keys/devServer.js deleted file mode 100644 index 69e0eee7c..000000000 --- a/packages/build-plugin-rax-component/src/config/user/keys/devServer.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - defaultValue: { - compress: true, - disableHostCheck: true, - clientLogLevel: 'error', - hot: true, - quiet: true, - overlay: false, - }, - validation: 'object', - configWebpack: (config, value, context) => { - const { command } = context; - - if (command === 'start') { - config.merge({ devServer: value }); - } - }, -}; diff --git a/packages/build-plugin-rax-component/src/config/user/keys/mockNodeEnv.js b/packages/build-plugin-rax-component/src/config/user/keys/mockNodeEnv.js deleted file mode 100644 index 5d4e8673d..000000000 --- a/packages/build-plugin-rax-component/src/config/user/keys/mockNodeEnv.js +++ /dev/null @@ -1,30 +0,0 @@ -const CONFIG = { - process: false, - global: false -}; - -/** - * support disable mock node env - * https://webpack.js.org/configuration/node/ - */ -module.exports = { - defaultValue: true, - validation: (val) => { - return typeof val === 'boolean' || typeof val === 'object'; - }, - configWebpack: (config, value, context) => { - const { command } = context; - - if (value === false) { - Object.keys(CONFIG).map(key => { - config.node - .set(key, CONFIG[key]); - }); - } else if (typeof value === 'object') { - Object.keys(value).map(key => { - config.node - .set(key, value[key]); - }); - } - }, -}; diff --git a/packages/build-plugin-rax-component/src/config/user/keys/outputDir.js b/packages/build-plugin-rax-component/src/config/user/keys/outputDir.js deleted file mode 100644 index 1c17e4704..000000000 --- a/packages/build-plugin-rax-component/src/config/user/keys/outputDir.js +++ /dev/null @@ -1,12 +0,0 @@ -const path = require('path'); - -module.exports = { - defaultValue: 'lib', - validation: 'string', - configWebpack: (config, value, context) => { - const { command, rootDir } = context; - if (command === 'build') { - config.output.path(path.resolve(rootDir, value)); - } - }, -}; diff --git a/packages/build-plugin-rax-component/src/config/user/keys/publicPath.js b/packages/build-plugin-rax-component/src/config/user/keys/publicPath.js deleted file mode 100644 index 2d00073b6..000000000 --- a/packages/build-plugin-rax-component/src/config/user/keys/publicPath.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - defaultValue: './', - validation: 'string', - configWebpack: (config, value, context) => { - const { command } = context; - - if (command === 'build') { - config.output.publicPath(value); - } - }, -}; diff --git a/packages/build-plugin-rax-component/src/config/user/setConfig.js b/packages/build-plugin-rax-component/src/config/user/setConfig.js deleted file mode 100644 index e1d43cafd..000000000 --- a/packages/build-plugin-rax-component/src/config/user/setConfig.js +++ /dev/null @@ -1,16 +0,0 @@ -const path = require('path'); -const klawSync = require('klaw-sync'); - -module.exports = (api) => { - const { registerUserConfig } = api; - const files = klawSync(path.resolve(__dirname, './keys')); - - const configArr = files.map(fileInfo => { - const keyName = path.basename(fileInfo.path).replace('.js', ''); - const keyConfig = require(fileInfo.path); - keyConfig.name = keyName; - return keyConfig; - }); - - registerUserConfig(configArr); -}; \ No newline at end of file diff --git a/packages/build-plugin-rax-component/src/config/web/getDev.js b/packages/build-plugin-rax-component/src/config/web/getDev.js deleted file mode 100644 index f6db41513..000000000 --- a/packages/build-plugin-rax-component/src/config/web/getDev.js +++ /dev/null @@ -1,112 +0,0 @@ -const path = require('path'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const { hmrClient } = require('rax-compile-config'); -const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const getBaseWebpack = require('../getBaseWebpack'); -const getDemos = require('../getDemos'); - -module.exports = (context, options) => { - const config = getBaseWebpack(context); - const { rootDir, taskName } = context; - const demos = getDemos(rootDir); - - demos.forEach(({ name, filePath }) => { - config - .entry(name) - .add(hmrClient) - .add(filePath); - - config.plugin(`html4${name}`).use(HtmlWebpackPlugin, [ - { - inject: true, - filename: demos.length === 1 && name === 'index' ? 'index.html' : name, - chunks: [name], - template: path.resolve(__dirname, '../demo.html'), - }, - ]); - }); - - config.output - .filename('[name].js'); - - if (options.forceInline) { - config.module - .rule('css') - .test(/\.css?$/) - .use('css') - .loader(require.resolve('stylesheet-loader')) - .options({ taskName }); - - config.module - .rule('less') - .test(/\.less?$/) - .use('css') - .loader(require.resolve('stylesheet-loader')) - .options({ taskName }) - .end() - .use('less') - .loader(require.resolve('less-loader')); - } else { - config.module - .rule('css') - .test(/\.css?$/) - .use('minicss') - .loader(MiniCssExtractPlugin.loader) - .end() - .use('css') - .loader(require.resolve('css-loader')) - .end() - .use('postcss') - .loader(require.resolve('postcss-loader')) - .options({ - ident: 'postcss', - plugins: () => [ - require('postcss-preset-env')({ - autoprefixer: { - flexbox: 'no-2009', - }, - stage: 3, - }), - require('postcss-plugin-rpx2vw')(), - ], - }); - - config.module - .rule('less') - .test(/\.less?$/) - .use('minicss') - .loader(MiniCssExtractPlugin.loader) - .end() - .use('css') - .loader(require.resolve('css-loader')) - .end() - .use('postcss') - .loader(require.resolve('postcss-loader')) - .options({ - ident: 'postcss', - plugins: () => [ - require('postcss-preset-env')({ - autoprefixer: { - flexbox: 'no-2009', - }, - stage: 3, - }), - require('postcss-plugin-rpx2vw')(), - ], - }) - .end() - .use('less') - .loader(require.resolve('less-loader')); - } - - // Extract css for SSR dev server - config.plugin('minicss') - .use(MiniCssExtractPlugin, [{ - filename: '[name].css', - }]); - - // rewrite a request that matches the /\/index/ pattern to /index.html. - config.devServer.set('historyApiFallback', true); - - return config; -}; diff --git a/packages/build-plugin-rax-component/src/config/weex/getDev.js b/packages/build-plugin-rax-component/src/config/weex/getDev.js deleted file mode 100644 index 61abd7808..000000000 --- a/packages/build-plugin-rax-component/src/config/weex/getDev.js +++ /dev/null @@ -1,37 +0,0 @@ -const { hmrClient } = require('rax-compile-config'); -const WeexFrameworkBanner = require('../../plugins/WeexFrameworkBannerPlugin'); -const getBaseWebpack = require('../getBaseWebpack'); -const getDemos = require('../getDemos'); - -module.exports = (context) => { - const config = getBaseWebpack(context); - - const { rootDir } = context; - - getDemos(rootDir).forEach(({ name, filePath }) => { - config.entry(name) - .add(hmrClient) - .add(filePath); - }); - - config.output - .filename('weex/[name].js'); - - config.plugin('weexFrame') - .use(WeexFrameworkBanner); - - config.module.rule('css') - .test(/\.css?$/) - .use('css') - .loader(require.resolve('stylesheet-loader')); - - config.module.rule('less') - .test(/\.less?$/) - .use('css') - .loader(require.resolve('stylesheet-loader')) - .end() - .use('less') - .loader(require.resolve('less-loader')); - - return config; -}; diff --git a/packages/build-plugin-rax-component/src/constants.js b/packages/build-plugin-rax-component/src/constants.js deleted file mode 100644 index 105d5bd66..000000000 --- a/packages/build-plugin-rax-component/src/constants.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - WEB: 'web', - WEEX: 'weex', - MINIAPP: 'miniapp', - WECHAT_MINIPROGRAM: 'wechat-miniprogram', - NODE: 'node', -}; diff --git a/packages/build-plugin-rax-component/src/dev.js b/packages/build-plugin-rax-component/src/dev.js deleted file mode 100644 index 44ea07fa7..000000000 --- a/packages/build-plugin-rax-component/src/dev.js +++ /dev/null @@ -1,134 +0,0 @@ -const ip = require('ip'); -const consoleClear = require('console-clear'); -const qrcode = require('qrcode-terminal'); -const chalk = require('chalk'); -const path = require('path'); -const { platformMap } = require('miniapp-builder-shared'); -const { handleWebpackErr } = require('rax-compile-config'); -const getDemos = require('./config/getDemos'); - -const watchLib = require('./watchLib'); - -const { WEB, WEEX, MINIAPP, WECHAT_MINIPROGRAM, NODE } = require('./constants'); - -module.exports = (api, options = {}) => { - const { registerTask, context, onHook, onGetWebpackConfig } = api; - const { rootDir, userConfig } = context; - const { devWatchLib } = userConfig; - const { targets = [] } = options; - - let devUrl = ''; - let devCompletedArr = []; - const demos = getDemos(rootDir); - - // set dev config - targets.forEach((target) => { - if ([WEB, WEEX, NODE].indexOf(target) > -1) { - const getDev = require(`./config/${target}/getDev`); - const config = getDev(context, options); - registerTask(`component-demo-${target}`, config); - } else if ([MINIAPP, WECHAT_MINIPROGRAM].indexOf(target) > -1) { - options[target] = options[target] || {}; - addMiniappTargetParam(target, options[target]); - const getDev = require('./config/miniapp/getBase'); - const config = getDev(context, target, options, onGetWebpackConfig); - registerTask(`component-demo-${target}`, config); - } - }); - - if (devWatchLib) { - onHook('after.start.devServer', () => { - watchLib(api, options); - }); - } - - onHook('after.start.compile', async(args) => { - devUrl = args.url; - devCompletedArr.push(args); - devCompileLog(); - }); - - - function devCompileLog() { - consoleClear(true); - let { err, stats } = devCompletedArr[0]; - - devCompletedArr.forEach((devInfo) => { - if (devInfo.err || devInfo.stats.hasErrors()) { - err = devInfo.err; - stats = devInfo.stats; - } - }); - - devCompletedArr = []; - - if (!handleWebpackErr(err, stats)) { - return; - } - - console.log(chalk.green('Rax development server has been started:')); - console.log(); - - if (targets.includes(WEB)) { - console.log(chalk.green('[Web] Development pages:')); - demos.forEach((demo) => console.log(' ', chalk.underline.white(devUrl + demo.name))); - console.log(); - } - - if (targets.includes(NODE)) { - console.log(chalk.green('[SSR] Development pages:')); - demos.forEach((demo) => console.log(' ', chalk.underline.white(`${devUrl}ssr/${demo.name}`))); - console.log(); - } - - if (targets.includes(WEEX)) { - console.log(chalk.green('[Weex] Development server at:')); - - demos.forEach((demo) => { - // Use Weex App to scan ip address (mobile phone can't visit localhost). - const weexUrl = `${devUrl}weex/${demo.name}.js?wh_weex=true`.replace(/^http:\/\/localhost/gi, function(match) { - // Called when matched - try { - return `http://${ip.address()}`; - } catch (error) { - console.log(chalk.yellow(`Get local IP address failed: ${error.toString()}`)); - return match; - } - }); - console.log(' ', chalk.underline.white(weexUrl)); - console.log(); - qrcode.generate(weexUrl, { small: true }); - console.log(); - }); - } - - Object.entries(platformMap).forEach(([platform, config]) => { - if (targets.includes(platform)) { - let outputPath = ''; - if (options[platform].distDir) { - outputPath = options[platform].distDir; - console.log(chalk.green(`[${config.name}] Component lib at: `)); - } else { - outputPath = `demo/${platform}`; - console.log(chalk.green(`[${config.name}] Use ali miniapp developer tools to open the following folder:`)); - } - console.log(' ', chalk.underline.white(path.resolve(rootDir, outputPath))); - console.log(); - } - }); - } -}; - -/** - * Add miniapp target param to match jsx2mp-loader config - * */ -function addMiniappTargetParam(target, originalConfig = {}) { - switch (target) { - case WECHAT_MINIPROGRAM: - originalConfig.platform = 'wechat'; - break; - default: - break; - } - originalConfig.mode = 'watch'; -} diff --git a/packages/build-plugin-rax-component/src/gulp/compile.js b/packages/build-plugin-rax-component/src/gulp/compile.js deleted file mode 100644 index 1f6d20c41..000000000 --- a/packages/build-plugin-rax-component/src/gulp/compile.js +++ /dev/null @@ -1,8 +0,0 @@ -const path = require('path'); - -module.exports = function compile() { - process.argv = process.argv.slice(0, 2); - process.argv.push('--gulpfile', path.resolve(__dirname, './gulpfile.js')); - process.argv.push('--cwd', process.cwd()); - require('gulp-cli')(); -}; diff --git a/packages/build-plugin-rax-component/src/gulp/filePatterns.js b/packages/build-plugin-rax-component/src/gulp/filePatterns.js deleted file mode 100644 index d0a0aa9b7..000000000 --- a/packages/build-plugin-rax-component/src/gulp/filePatterns.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - JS_FILES_PATTERN: 'src/**/+(*.js|*.jsx)', - TS_FILES_PATTERN: 'src/**/+(*.ts|*.tsx)', - OTHER_FILES_PATTERN: 'src/**/!(*.js|*.jsx|*.ts|*.tsx)', - IGNORE_PATTERN: '**/__tests__/**', -}; diff --git a/packages/build-plugin-rax-component/src/gulp/gulpfile.js b/packages/build-plugin-rax-component/src/gulp/gulpfile.js deleted file mode 100644 index 3e0815629..000000000 --- a/packages/build-plugin-rax-component/src/gulp/gulpfile.js +++ /dev/null @@ -1,139 +0,0 @@ -const fs = require('fs-extra'); -const path = require('path'); -const { src, dest, series, parallel, watch } = require('gulp'); -const babel = require('gulp-babel'); -const ts = require('gulp-typescript'); -const getBabelConfig = require('rax-babel-config'); - -const { - JS_FILES_PATTERN, - TS_FILES_PATTERN, - OTHER_FILES_PATTERN, - IGNORE_PATTERN, -} = require('./filePatterns'); - -const params = require('./params'); - -const babelOptions = { - styleSheet: true, - custom: { - ignore: ['**/**/*.d.ts'], - }, -}; -const babelConfig = getBabelConfig({ - ...babelOptions -}); -const esBabelConfig = getBabelConfig({ - ...babelOptions, - modules: false, -}); - -const { - api, - options, - callback = done => { - done(); - }, -} = params; - -const { context } = api; -const { rootDir, userConfig, command } = context; -const { esOutputDir = 'es' } = options; - -const isDev = command === 'dev'; - -const enableTypescript = fs.existsSync(path.join(rootDir, 'tsconfig.json')); - -const LIB_DIR = 'lib'; -const ES_DIR = esOutputDir ? path.resolve(rootDir, esOutputDir) : ''; - -// for js/jsx. -function compileJs() { - return src([JS_FILES_PATTERN], { ignore: IGNORE_PATTERN }) - .pipe(babel(babelConfig)) - .pipe(dest(LIB_DIR)); -} - -function compileJS2ES() { - if (!ES_DIR) { - return src('.'); - } - - return src([JS_FILES_PATTERN], { ignore: IGNORE_PATTERN }) - .pipe(babel(esBabelConfig)) - .pipe(dest(ES_DIR)); -} - -const tsProject = ts.createProject('tsconfig.json', { - skipLibCheck: true, - outDir: LIB_DIR, -}); - -// for ts/tsx. -function compileTs() { - return tsProject - .src() - .pipe(tsProject()) - .pipe(babel(babelConfig)) - .pipe(dest(LIB_DIR)); -} - -const tsProject4Dts = ts.createProject('tsconfig.json', { - skipLibCheck: true, - declaration: true, -}); - -function compileDts() { - return tsProject4Dts.src() - .pipe(tsProject4Dts()) - .dts - .pipe(dest(LIB_DIR)) - .pipe(dest(ES_DIR)); -} - -const tsProject4ES = ts.createProject('tsconfig.json', { - skipLibCheck: true, - outDir: ES_DIR, -}); - -function compileTS2ES() { - if (!ES_DIR) { - return src('.'); - } - return tsProject4ES.src() - .pipe(tsProject4ES()) - .pipe(babel(esBabelConfig)) - .pipe(dest(ES_DIR)); -} - -function copyOther() { - const task = src([OTHER_FILES_PATTERN], { ignore: IGNORE_PATTERN }).pipe(dest(LIB_DIR)); - return ES_DIR ? task.pipe(dest(ES_DIR)) : task; -} - -if (isDev) { - watch([JS_FILES_PATTERN], { ignore: IGNORE_PATTERN }, compileJs); - watch([OTHER_FILES_PATTERN], { ignore: IGNORE_PATTERN }, copyOther); - - if (enableTypescript) { - watch([TS_FILES_PATTERN], { ignore: IGNORE_PATTERN }, compileTs); - } -} - -let tasks = [compileJs]; - -if (enableTypescript) { - tasks = [...tasks, compileDts, compileTs]; -} - -if (ES_DIR) { - tasks = [...tasks, compileJS2ES]; - - if (enableTypescript) { - tasks = [...tasks, compileTS2ES]; - } -} - -tasks = [parallel(...tasks, copyOther)]; - -exports.default = series(...tasks, callback); diff --git a/packages/build-plugin-rax-component/src/gulp/params.js b/packages/build-plugin-rax-component/src/gulp/params.js deleted file mode 100644 index cc1930eb6..000000000 --- a/packages/build-plugin-rax-component/src/gulp/params.js +++ /dev/null @@ -1,2 +0,0 @@ -const params = {}; -module.exports = params; diff --git a/packages/build-plugin-rax-component/src/index.js b/packages/build-plugin-rax-component/src/index.js deleted file mode 100644 index 4f53bfc21..000000000 --- a/packages/build-plugin-rax-component/src/index.js +++ /dev/null @@ -1,29 +0,0 @@ -const deepmerge = require('deepmerge'); -const chalk = require('chalk'); -const setUserConfig = require('./config/user/setConfig'); -const defaultUserConfig = require('./config/user/default.config'); -const dev = require('./dev'); -const build = require('./build'); - -module.exports = (api, options = {}) => { - setUserConfig(api, options); - - api.setValue('targets', options.targets); - - if (!(options.targets && options.targets.length)) { - console.error(chalk.red('rax-plugin-component need to set targets, e.g. ["rax-plugin-component", targets: ["web", "weex"]]')); - console.log(); - process.exit(1); - } - api.context.userConfig = deepmerge(defaultUserConfig, api.context.userConfig); - const { command } = api.context; - - // set dev config - if (command === 'start') { - dev(api, options); - } - - if (command === 'build') { - build(api, options); - } -}; diff --git a/packages/build-plugin-rax-component/src/loaders/MarkdownLoader/index.js b/packages/build-plugin-rax-component/src/loaders/MarkdownLoader/index.js deleted file mode 100644 index 4c5508d7c..000000000 --- a/packages/build-plugin-rax-component/src/loaders/MarkdownLoader/index.js +++ /dev/null @@ -1,12 +0,0 @@ -const path = require('path'); -const parseMD = require('../../config/parseMarkdown'); - -module.exports = function(content) { - const resourcePath = this.resourcePath; - const ext = path.extname(resourcePath); - const name = path.basename(resourcePath, ext); - - const result = parseMD(name, content, resourcePath); - - return result.js; -}; diff --git a/packages/build-plugin-rax-component/src/plugins/WeexFrameworkBannerPlugin.js b/packages/build-plugin-rax-component/src/plugins/WeexFrameworkBannerPlugin.js deleted file mode 100644 index 2260f4ec7..000000000 --- a/packages/build-plugin-rax-component/src/plugins/WeexFrameworkBannerPlugin.js +++ /dev/null @@ -1,65 +0,0 @@ -const { ConcatSource } = require('webpack-sources'); - -class WeexFrameworkBannerPlugin { - constructor(options) { - this.options = Object.assign({ - framework: 'Rax', - }, options); - } - - apply(compiler) { - const frameworkComment = `// {"framework" : "${this.options.framework}"}`; - - // Webpack 4 - if (compiler.hooks && compiler.hooks.compilation && compiler.hooks.compilation.tap) { - compiler.hooks.compilation.tap('WeexFrameworkBannerPlugin', compilation => { - // uglify-webpack-plugin will remove javascript's comments in optimizeChunkAssets - // need use afterOptimizeChunkAssets to add frameworkComment after that. - // like the else block - compilation.hooks.afterOptimizeChunkAssets.tap('WeexFrameworkBannerPlugin', chunks => { - for (const chunk of chunks) { - // Entry only - if (!chunk.canBeInitial()) { - continue; // eslint-disable-line - } - - chunk.files.forEach(function(file) { - compilation.assets[file] = new ConcatSource( - frameworkComment, - '\n', - compilation.assets[file], - ); - }); - } - }); - }); - } else { - compiler.plugin('compilation', (compilation) => { - // uglify-webpack-plugin will remove javascript's comments in - // optimize-chunk-assets, add frameworkComment after that. - compilation.plugin('after-optimize-chunk-assets', function(chunks) { - chunks.forEach(function(chunk) { - // Entry only - try { - // In webpack2 chunk.initial was removed. Use isInitial() - if (!chunk.initial) return; - } catch (e) { - if (!chunk.isInitial()) return; - } - - chunk.files.forEach(function(file) { - compilation.assets[file] = new ConcatSource( - frameworkComment, - '\n', - compilation.assets[file], - ); - }); - }); - }); - }); - } - } -} - - -module.exports = WeexFrameworkBannerPlugin; diff --git a/packages/build-plugin-rax-component/src/watchLib.js b/packages/build-plugin-rax-component/src/watchLib.js deleted file mode 100644 index dbd7c8e47..000000000 --- a/packages/build-plugin-rax-component/src/watchLib.js +++ /dev/null @@ -1,9 +0,0 @@ -const gulpCompile = require('./gulp/compile'); -const gulpParams = require('./gulp/params'); - -module.exports = async(api, options) => { - gulpParams.api = api; - gulpParams.options = options; - - gulpCompile(); -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/README.md b/packages/build-plugin-rax-miniapp-plugin/README.md deleted file mode 100644 index 78731c0c8..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# build-plugin-rax-miniapp-plugin [![npm](https://img.shields.io/npm/v/build-plugin-rax-miniapp-plugin.svg)](https://www.npmjs.com/package/build-plugin-rax-miniapp-plugin) - -`build-scripts` plugin which contains base configuration of rax miniapp plugin - -## Usage - -```json -{ - "plugins": [ - "build-plugin-rax-miniapp-plugin" - ] -} -``` diff --git a/packages/build-plugin-rax-miniapp-plugin/package.json b/packages/build-plugin-rax-miniapp-plugin/package.json deleted file mode 100644 index 3f8cbf160..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/package.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "build-plugin-rax-miniapp-plugin", - "version": "0.1.0", - "description": "rax miniapp-plugin base plugins", - "main": "src/index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [ - "plugin", - "rax", - "miniapp plugin" - ], - "author": "", - "license": "MIT", - "peerDependencies": { - "@alib/build-scripts": "^0.1.0", - "rax": "^1.0.0" - }, - "dependencies": { - "babel-loader": "8.0.4", - "chalk": "^2.4.2", - "chokidar": "^3.3.1", - "console-clear": "^1.1.1", - "fs-extra": "^8.1.0", - "json-loader": "^0.5.7", - "jsx2mp-loader": "^0.4.0", - "jsx2mp-runtime": "^0.4.1", - "klaw-sync": "^6.0.0", - "loader-utils": "^1.1.0", - "lodash": "^4.17.15", - "memory-fs": "^0.5.0", - "miniapp-element": "^0.1.0", - "miniapp-render": "^0.1.1", - "rax-compile-config": "^0.2.0", - "terser": "^4.6.4", - "ts-loader": "^5.3.3", - "typescript": "^3.2.4", - "webpack": "^4.27.1", - "webpack-chain": "^6.0.0" - } -} diff --git a/packages/build-plugin-rax-miniapp-plugin/src/build.js b/packages/build-plugin-rax-miniapp-plugin/src/build.js deleted file mode 100644 index 114f6e602..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/build.js +++ /dev/null @@ -1,54 +0,0 @@ -const path = require('path'); -const chalk = require('chalk'); -const consoleClear = require('console-clear'); -const { handleWebpackErr } = require('rax-compile-config'); - -const getMiniAppOutput = require('./config/getOutputPath'); - -const { MINIAPP, WECHAT_MINIPROGRAM } = require('./constants'); - -module.exports = ({ onGetWebpackConfig, registerTask, context, onHook }, options = {}) => { - const { targets = [] } = options; - - targets.forEach(async(target) => { - const getBase = require('./config/getBase'); - registerTask(target, getBase(context, target, options, onGetWebpackConfig)); - }); - - onHook('after.build.compile', ({ err, stats }) => { - consoleClear(true); - if (!handleWebpackErr(err, stats)) { - return; - } - logBuildResult(targets, context); - }); -}; - -/** - * Log build result - * @param {array} targets - * @param {object} context - */ -function logBuildResult(targets = [], context = {}) { - const { rootDir, userConfig = {} } = context; - const { outputDir } = userConfig; - - console.log(chalk.green('Rax build finished:')); - console.log(); - - if (targets.includes(MINIAPP)) { - console.log(chalk.green('[Alibaba MiniApp] Plugin Bundle at:')); - console.log(' ', chalk.underline.white(getMiniAppOutput(context, { - target: MINIAPP, - }))); - console.log(); - } - - if (targets.includes(WECHAT_MINIPROGRAM)) { - console.log(chalk.green('[WeChat MiniProgram] Plugin Bundle at:')); - console.log(' ', chalk.underline.white(getMiniAppOutput(context, { - target: WECHAT_MINIPROGRAM, - }))); - console.log(); - } -} diff --git a/packages/build-plugin-rax-miniapp-plugin/src/config/getBase.js b/packages/build-plugin-rax-miniapp-plugin/src/config/getBase.js deleted file mode 100644 index 854a30d5e..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/config/getBase.js +++ /dev/null @@ -1,188 +0,0 @@ -const webpack = require('webpack'); -const Chain = require('webpack-chain'); -const { resolve } = require('path'); -const { existsSync } = require('fs-extra'); - -const getPluginConfig = require('./getPluginConfig'); -const setEntry = require('./setEntry'); -const getOutputPath = require('./getOutputPath'); - -const ModifyOutputFileSystemPlugin = require('../plugins/miniapp/ModifyOutputFileSystem'); -const CopyJsx2mpRuntimePlugin = require('../plugins/miniapp/CopyJsx2mpRuntime'); -const CopyPublicFilePlugin = require('../plugins/miniapp/CopyPublicFile'); -const ProcessPluginJsonPlugin = require('../plugins/miniapp/ProcessPluginJson'); -const GenerateAppCssPlugin = require('../plugins/miniapp/GenerateAppCss'); - -const platformConfig = require('./platformConfig'); -const targetPlatformMap = require('./targetPlatformMap'); - -const PageLoader = require.resolve('jsx2mp-loader/src/page-loader'); -const ComponentLoader = require.resolve('jsx2mp-loader/src/component-loader'); -const ScriptLoader = require.resolve('jsx2mp-loader/src/script-loader'); -const FileLoader = require.resolve('jsx2mp-loader/src/file-loader'); - -module.exports = (context, target, options = {}, onGetWebpackConfig) => { - const { platform = targetPlatformMap[target], mode = 'build', disableCopyNpm = false, turnOffSourceMap = false } = options[target] || {}; - const { rootDir, command } = context; - const platformInfo = platformConfig[target]; - const entryPath = './src/index'; - const outputPath = getOutputPath(context, { target }); - - const config = new Chain(); - - const pluginConfig = getPluginConfig(rootDir, target); - - const isPublicFileExist = existsSync(resolve(rootDir, 'src/public')); - const constantDir = isPublicFileExist ? ['src/public'] : []; - - const loaderParams = { - mode, - entryPath, - outputPath, - constantDir, - disableCopyNpm, - turnOffSourceMap, - injectAppCssComponent: true, - platform: platformInfo - }; - const pageLoaderParams = { - ...loaderParams, - entryPath - }; - - - setEntry(config, pluginConfig, { entryPath }); - - config.target('web'); - config.context(rootDir); - - config.plugin('noError') - .use(webpack.NoEmitOnErrorsPlugin); - - if (command === 'start') { - config.mode('development'); - } - - config - .mode('production') - .target('node'); - - config.resolve.alias - .set('react', 'rax') - .set('react-dom', 'rax-dom'); - - onGetWebpackConfig(target, (config) => { - const aliasEntries = config.resolve.alias.entries(); - loaderParams.aliasEntries = pageLoaderParams.aliasEntries = aliasEntries; - }); - - config.module.rule('jsx').uses.clear(); - config.module.rule('tsx').uses.clear(); - config.module.rule('tsx') - .test(/\.(tsx?)$/) - .use('ts') - .loader(require.resolve('ts-loader')) - .options({ - transpileOnly: true, - }); - - - // Remove all app.json before it - config.module.rule('appJSON').uses.clear(); - - config.module.rule('withRoleJSX') - .test(/\.t|jsx?$/) - .enforce('post') - .exclude - .add(/node_modules/) - .end() - .use('page') - .loader(PageLoader) - .options(pageLoaderParams) - .end() - .use('component') - .loader(ComponentLoader) - .options(pageLoaderParams) - .end() - .use('platform') - .loader(require.resolve('rax-compile-config/src/platformLoader')) - .options({platform: target}) - .end() - .use('script') - .loader(ScriptLoader) - .options(loaderParams) - .end(); - - config.module.rule('npm') - .test(/\.js$/) - .include - .add(/node_modules/) - .end() - .use('script') - .loader(ScriptLoader) - .options(loaderParams) - .end(); - - config.module - .rule('staticFile') - .test(/\.(bmp|webp|svg|png|webp|jpe?g|gif)$/i) - .use('file') - .loader(FileLoader) - .options({ - entryPath, - outputPath - }); - - config.module - .rule('json') - .test(/\.json$/) - .use('script-loader') - .loader(ScriptLoader) - .options(loaderParams) - .end() - .use('json-loader') - .loader(require.resolve('json-loader')); - - - config.resolve.extensions - .merge(['.js', '.json', '.jsx', '.ts', '.tsx']); - - - config.resolve.mainFields - .add('main').add('module'); - - config.externals([ - function(ctx, request, callback) { - if (/^@core\//.test(request)) { - return callback(null, `commonjs2 ${request}`); - } - if (/\.(css|sass|scss|styl|less)$/.test(request)) { - return callback(null, `commonjs2 ${request}`); - } - if (/^@weex-module\//.test(request)) { - return callback(null, `commonjs2 ${request}`); - } - callback(); - }, - ]); - - config.plugin('define').use(webpack.DefinePlugin, [{ - 'process.env': { - NODE_ENV: mode === 'build' ? '"production"' : '"development"' - } - }]); - config.plugin('watchIgnore').use(webpack.WatchIgnorePlugin, [[/node_modules/]]); - config.plugin('modifyOutputFileSystem').use(ModifyOutputFileSystemPlugin); - config.plugin('processPluginJson').use(ProcessPluginJsonPlugin, [{ outputPath, rootDir, target }]); - config.plugin('generateAppCss').use(GenerateAppCssPlugin, [{ outputPath, platformInfo }]); - - if (isPublicFileExist) { - config.plugin('copyFile').use(CopyPublicFilePlugin, [{ mode, outputPath, rootDir }]); - } - - if (!disableCopyNpm) { - config.plugin('runtime').use(CopyJsx2mpRuntimePlugin, [{ platform, mode, outputPath, rootDir }]); - } - - return config; -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/config/getOutputPath.js b/packages/build-plugin-rax-miniapp-plugin/src/config/getOutputPath.js deleted file mode 100644 index 55a1799d6..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/config/getOutputPath.js +++ /dev/null @@ -1,18 +0,0 @@ -const fs = require('fs-extra'); -const path = require('path'); -const { MINIAPP } = require('../constants'); - -module.exports = (context, { target = MINIAPP, demoClientFolder = false}) => { - const { rootDir, userConfig, command } = context; - const { outputDir } = userConfig; - if (command === 'build') { - const output = path.resolve(rootDir, outputDir); - fs.ensureDirSync(output); - return path.resolve(output, target); - } else { - if (demoClientFolder) { - return path.resolve(rootDir, 'demo', target); - } - return path.resolve(rootDir, 'demo', target, 'plugin'); - } -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/config/getPluginConfig.js b/packages/build-plugin-rax-miniapp-plugin/src/config/getPluginConfig.js deleted file mode 100644 index 8c5e55892..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/config/getPluginConfig.js +++ /dev/null @@ -1,7 +0,0 @@ -const { resolve } = require('path'); -const { readJSONSync } = require('fs-extra'); - -module.exports = (rootDir) => { - const pluginConfig = readJSONSync(resolve(rootDir, 'src', 'plugin.json')); - return pluginConfig; -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/config/platformConfig.js b/packages/build-plugin-rax-miniapp-plugin/src/config/platformConfig.js deleted file mode 100644 index 14fd265d5..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/config/platformConfig.js +++ /dev/null @@ -1,38 +0,0 @@ -const { MINIAPP, WECHAT_MINIPROGRAM } = require('../constants'); - - -module.exports = { - [MINIAPP]: { - type: 'ali', - name: 'Alibaba MiniApp', - extension: { - xml: '.axml', - css: '.acss', - } - }, - [WECHAT_MINIPROGRAM]: { - type: 'wechat', - name: 'WeChat MiniProgram', - extension: { - xml: '.wxml', - css: '.wxss', - } - }, - // Wait for implementation - // 'baidu': { - // type: 'baidu', - // name: 'Baidu SmartProgram', - // extension: { - // xml: '.swan', - // css: '.css', - // } - // }, - // 'bytedance': { - // type: 'bytedance', - // name: 'ByteDance MicroApp', - // extension: { - // xml: '.ttml', - // css: '.ttss' - // } - // } -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/config/setEntry.js b/packages/build-plugin-rax-miniapp-plugin/src/config/setEntry.js deleted file mode 100644 index 12040207d..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/config/setEntry.js +++ /dev/null @@ -1,54 +0,0 @@ -const { dirname, join, sep, extname } = require('path'); - -/** - * ./pages/foo -> based on src, return original - * /pages/foo -> based on rootContext - * pages/foo -> based on src, add prefix: './' or '.\' - */ -function getDepPath(source, rootDir) { - if (source[0] === '.' || source[0] === sep) { - return join(rootDir, source); - } - return ['.', rootDir, source].join(sep); -} - -/** - * Remove file extension - * @param {string} filePath - */ -function removeExt(filePath) { - const lastDot = filePath.lastIndexOf('.'); - return filePath.slice(0, lastDot); -} - -function getEntry(entryIndexFilePath, pluginConfig) { - const { pages, publicComponents, main } = pluginConfig; - const rootDir = dirname(entryIndexFilePath); - const entry = {}; - - if (pages) { - Object.keys(pages).forEach(pageName => { - entry[`@${pageName}`] = `${getDepPath(pages[pageName], rootDir)}?role=page`; - }); - } - if (publicComponents) { - Object.keys(publicComponents).forEach(compName => { - entry[`@${compName}`] = `${getDepPath(publicComponents[compName], rootDir)}?role=component`; - }); - } - if (main) { - entry.main = removeExt(getDepPath(main, rootDir)); - } - return entry; -} - -module.exports = (config, pluginConfig, options) => { - config.entryPoints.clear(); - const { entryPath } = options; - const entries = getEntry(entryPath, pluginConfig); - for (const [entryName, source] of Object.entries(entries)) { - const entryConfig = config.entry(entryName); - entryConfig.add(source); - } -}; - diff --git a/packages/build-plugin-rax-miniapp-plugin/src/config/targetPlatformMap.js b/packages/build-plugin-rax-miniapp-plugin/src/config/targetPlatformMap.js deleted file mode 100644 index b69b6a9e4..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/config/targetPlatformMap.js +++ /dev/null @@ -1,6 +0,0 @@ -const { MINIAPP, WECHAT_MINIPROGRAM } = require('../constants'); - -module.exports = { - [MINIAPP]: 'ali', - [WECHAT_MINIPROGRAM]: 'wechat' -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/config/user/keys/alias.js b/packages/build-plugin-rax-miniapp-plugin/src/config/user/keys/alias.js deleted file mode 100644 index 1686df696..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/config/user/keys/alias.js +++ /dev/null @@ -1,21 +0,0 @@ -const path = require('path'); -const { existsSync } = require('fs-extra'); - -module.exports = { - defaultValue: {}, - validation: 'object', - configWebpack: (config, value, context) => { - // "alias": { - // "@components": "src/components/", - // "react": "rax" - // } - Object.keys(value).forEach((alias) => { - const fullPath = path.resolve(context.rootDir, value[alias]); - if (existsSync(fullPath)) { - config.resolve.alias.set(alias, fullPath); - } else { - config.resolve.alias.set(alias, value[alias]); - } - }); - }, -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/config/user/keys/devServer.js b/packages/build-plugin-rax-miniapp-plugin/src/config/user/keys/devServer.js deleted file mode 100644 index 69e0eee7c..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/config/user/keys/devServer.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - defaultValue: { - compress: true, - disableHostCheck: true, - clientLogLevel: 'error', - hot: true, - quiet: true, - overlay: false, - }, - validation: 'object', - configWebpack: (config, value, context) => { - const { command } = context; - - if (command === 'start') { - config.merge({ devServer: value }); - } - }, -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/config/user/keys/outputDir.js b/packages/build-plugin-rax-miniapp-plugin/src/config/user/keys/outputDir.js deleted file mode 100644 index d4324200b..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/config/user/keys/outputDir.js +++ /dev/null @@ -1,10 +0,0 @@ -const path = require('path'); - -module.exports = { - defaultValue: 'build', - validation: 'string', - configWebpack: (config, value, context) => { - const { rootDir } = context; - config.output.path(path.resolve(rootDir, value)); - }, -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/config/user/setConfig.js b/packages/build-plugin-rax-miniapp-plugin/src/config/user/setConfig.js deleted file mode 100644 index 2d4518f59..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/config/user/setConfig.js +++ /dev/null @@ -1,16 +0,0 @@ -const path = require('path'); -const klawSync = require('klaw-sync'); - -module.exports = (api) => { - const { registerUserConfig } = api; - const files = klawSync(path.resolve(__dirname, './keys')); - - const configArr = files.map(fileInfo => { - const keyName = path.basename(fileInfo.path).replace('.js', ''); - const keyConfig = require(fileInfo.path); - keyConfig.name = keyName; - return keyConfig; - }); - - registerUserConfig(configArr); -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/constants.js b/packages/build-plugin-rax-miniapp-plugin/src/constants.js deleted file mode 100644 index 96727821f..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/constants.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - MINIAPP: 'miniapp', - WECHAT_MINIPROGRAM: 'wechat-miniprogram', -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/dev.js b/packages/build-plugin-rax-miniapp-plugin/src/dev.js deleted file mode 100644 index 5c0be6ae6..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/dev.js +++ /dev/null @@ -1,67 +0,0 @@ -const chalk = require('chalk'); -const { resolve } = require('path'); -const consoleClear = require('console-clear'); - -const { handleWebpackErr } = require('rax-compile-config'); -const getMiniAppOutput = require('./config/getOutputPath'); - -const { MINIAPP, WECHAT_MINIPROGRAM } = require('./constants'); - -module.exports = ({ onGetWebpackConfig, registerTask, context, onHook }, options = {}) => { - const { targets = [] } = options; - let devCompletedArr = []; - - targets.forEach((target, index) => { - const getBase = getConfig(target, options); - registerTask(target, getBase(context, target, options, onGetWebpackConfig)); - }); - - onHook('after.start.compile', async(args) => { - devCompletedArr.push(args); - devCompileLog(); - }); - - function devCompileLog() { - let err = devCompletedArr[0].err; - let stats = devCompletedArr[0].stats; - - if (!handleWebpackErr(err, stats)) { - return; - } - - consoleClear(true); - - devCompletedArr.forEach((devInfo) => { - if (devInfo.err || devInfo.stats.hasErrors()) { - err = devInfo.err; - stats = devInfo.stats; - } - }); - - devCompletedArr = []; - - console.log(chalk.green('Rax development server has been started:')); - console.log(); - - if (targets.includes(MINIAPP)) { - console.log(chalk.green('[Ali Miniapp] Use ali miniapp developer tools to open the following folder:')); - console.log(' ', chalk.underline.white(getMiniAppOutput(context, { target: MINIAPP, demoClientFolder: true }))); - console.log(); - } - - if (targets.includes(WECHAT_MINIPROGRAM)) { - console.log(chalk.green('[WeChat MiniProgram] Use wechat miniprogram developer tools to open the following folder:')); - console.log(' ', chalk.underline.white(getMiniAppOutput(context, { target: WECHAT_MINIPROGRAM, demoClientFolder: true }))); - console.log(); - } - } -}; - -function getConfig(target, options = {}) { - if (options[target]) { - options[target].mode = 'watch'; - } else { - options[target] = { mode: 'watch' }; - } - return require('./config/getBase'); -} diff --git a/packages/build-plugin-rax-miniapp-plugin/src/index.js b/packages/build-plugin-rax-miniapp-plugin/src/index.js deleted file mode 100644 index bc412e2df..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/index.js +++ /dev/null @@ -1,52 +0,0 @@ -const chalk = require('chalk'); -const setUserConfig = require('./config/user/setConfig'); - -const build = require('./build'); -const dev = require('./dev'); - -const pluginApp = (api, options = {}) => { - enterCheck(api, options); - - api.setValue('targets', options.targets); - - const { context } = api; - const { command } = context; - - setUserConfig(api, options); - - if (command === 'build') { - build(api, options); - } - - if (command === 'start') { - dev(api, options); - } -}; - -function enterCheck(api, options) { - const { context, log } = api; - const { plugins } = context.userConfig; - - let errMsg = ''; - let hasError = false; - - const firstPluginName = Array.isArray(plugins[0]) ? plugins[0][0] : plugins[0]; - - if (firstPluginName !== 'build-plugin-rax-miniapp-plugin') { - errMsg = 'build-plugin-rax-miniapp-plugin must be the first plugin, please check the order of plugins'; - hasError = true; - } - - if (!(options.targets && options.targets.length)) { - errMsg = 'build-plugin-rax-miniapp-plugin need to set targets, e.g. ["build-plugin-rax-app", targets: ["miniapp", "wechat-miniprogram"]]'; - hasError = true; - } - - if (hasError) { - log.error(chalk.red(errMsg)); - console.log(); - process.exit(1); - } -} - -module.exports = pluginApp; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/CopyJsx2mpRuntime.js b/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/CopyJsx2mpRuntime.js deleted file mode 100644 index a252675a0..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/CopyJsx2mpRuntime.js +++ /dev/null @@ -1,63 +0,0 @@ -const { join } = require('path'); -const { copySync, writeFileSync, ensureFileSync, readJSONSync, readFileSync } = require('fs-extra'); -const { minify } = require('terser'); - -/** - * Runtime packages should be a dependency of build-plugin-rax-app. But if the project has installed it, then it will take the priority. - * @param {string} packageName - * @param {string} rootDir - */ -function getHighestPriorityPackageJSON(packageName, rootDir) { - const targetFile = join(packageName, 'package.json'); - const resolvePaths = require.resolve.paths(targetFile); - resolvePaths.unshift(join(rootDir, 'node_modules')); - const packageJSONPath = require.resolve(targetFile, { - paths: resolvePaths - }); - return packageJSONPath; -} - -const runtime = 'jsx2mp-runtime'; -let runtimePackageJSONPath = null; -let runtimePackageJSON = null; -let runtimePackagePath = null; - -/** - * For convenient to copy vendors. - */ -module.exports = class JSX2MPRuntimePlugin { - constructor({ platform = 'ali', mode = 'build', rootDir = '', outputPath = '' }) { - this.platform = platform; - this.mode = mode; - this.rootDir = rootDir; - this.outputPath = outputPath; - } - - apply(compiler) { - compiler.hooks.emit.tapAsync( - 'JSX2MPRuntimePlugin', - (compilation, callback) => { - if (!runtimePackageJSONPath) { - runtimePackageJSONPath = getHighestPriorityPackageJSON(runtime, this.rootDir); - runtimePackageJSON = readJSONSync(runtimePackageJSONPath); - runtimePackagePath = join(runtimePackageJSONPath, '..'); - } - - const runtimeTargetPath = runtimePackageJSON.miniprogram && runtimePackageJSON.miniprogram[this.platform] - ? runtimePackageJSON.miniprogram[this.platform] - : runtimePackageJSON.main || 'index.js'; - const sourceFile = require.resolve(join(runtimePackagePath, runtimeTargetPath)); - const targetFile = join(this.outputPath, 'npm', runtime + '.js'); - ensureFileSync(targetFile); - if (this.mode === 'build') { - const sourceCode = minify(readFileSync(sourceFile, 'utf-8')).code; - writeFileSync(targetFile, sourceCode); - } else { - copySync(sourceFile, targetFile); - } - - callback(); - } - ); - } -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/CopyPublicFile.js b/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/CopyPublicFile.js deleted file mode 100644 index 5581d5bd6..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/CopyPublicFile.js +++ /dev/null @@ -1,41 +0,0 @@ -const { resolve } = require('path'); -const { copySync } = require('fs-extra'); -const chokidar = require('chokidar'); - - -function copyFile(srcPath, distPath) { - copySync(srcPath, distPath, { - filter: (file) => !/\.js$/.test(file) - }); -} - -/** - * Copy public directories to dist - */ -module.exports = class CopyPublicFilePlugin { - constructor({ mode = 'build', rootDir = '', outputPath = '' }) { - this.mode = mode; - this.rootDir = rootDir; - this.outputPath = outputPath; - } - - apply(compiler) { - compiler.hooks.emit.tapAsync( - 'CopyPublicFilePlugin', - (compilation, callback) => { - const publicFilePath = resolve(this.rootDir, 'src/public'); - const distPublicFilePath = resolve(this.outputPath, 'public'); - - if (this.mode === 'build') { - copyFile(publicFilePath, distPublicFilePath); - } else { - const publicWatcher = chokidar.watch(publicFilePath); - publicWatcher.on('all', () => { - copyFile(publicFilePath, distPublicFilePath); - }); - } - callback(); - } - ); - } -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/GenerateAppCss.js b/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/GenerateAppCss.js deleted file mode 100644 index 49c5f6934..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/GenerateAppCss.js +++ /dev/null @@ -1,32 +0,0 @@ -const { resolve } = require('path'); -const { copySync, outputFile } = require('fs-extra'); -const chokidar = require('chokidar'); - -/** - * In plugin mode, app.acss/wxss doesn't exist so that __rax-view can't be placed which will affect the page/component which uses rax-view - * This plugin generates a custom component just for import its css which contains __rax-view - */ -module.exports = class GenerateAppCssPlugin { - constructor({ outputPath = '', platformInfo = {} }) { - this.outputPath = outputPath; - this.platformInfo = platformInfo; - } - - apply(compiler) { - compiler.hooks.emit.tapAsync( - 'GenerateAppCssPlugin', - (compilation, callback) => { - const componentJS = 'Component({});'; - const componentJSON = '{"component":true}'; - const componentXML = ''; - const componentCSS = '.__rax-view {border: 0 solid black;display:flex;flex-direction:column;align-content:flex-start;flex-shrink:0;box-sizing:border-box;}'; - - outputFile(resolve(this.outputPath, '__app_css', 'index.js'), componentJS); - outputFile(resolve(this.outputPath, '__app_css', 'index.json'), componentJSON); - outputFile(resolve(this.outputPath, '__app_css', `index${this.platformInfo.extension.xml}`), componentXML); - outputFile(resolve(this.outputPath, '__app_css', `index${this.platformInfo.extension.css}`), componentCSS); - callback(); - } - ); - } -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/ModifyOutputFileSystem.js b/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/ModifyOutputFileSystem.js deleted file mode 100644 index 8abb306df..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/ModifyOutputFileSystem.js +++ /dev/null @@ -1,7 +0,0 @@ -const MemFs = require('memory-fs'); - -module.exports = class ModifyOutputFileSystemPlugin { - apply(compiler) { - compiler.outputFileSystem = new MemFs(); - } -}; diff --git a/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/ProcessPluginJson.js b/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/ProcessPluginJson.js deleted file mode 100644 index b481c7696..000000000 --- a/packages/build-plugin-rax-miniapp-plugin/src/plugins/miniapp/ProcessPluginJson.js +++ /dev/null @@ -1,48 +0,0 @@ -const { resolve } = require('path'); -const { copy, readJSONSync, writeJSON } = require('fs-extra'); -const chokidar = require('chokidar'); -const { MINIAPP, WECHAT_MINIPROGRAM } = require('../../constants'); - - -/** - * In Alipay, pages must be an array, while in Wechat pages is an object. - * So here pages need to be transformed. - * @param {string} pluginPath - */ -function transformPluginContent(pluginPath) { - const content = readJSONSync(pluginPath); - if (content.pages) { - content.pages = Object.entries(content.pages).map(([pageName, pagePath]) => pagePath); - } - return content; -} -/** - * Process plugin json content and write to dist - */ -module.exports = class ProcessPluginJsonPlugin { - constructor({ rootDir = '', outputPath = '', target = MINIAPP }) { - this.rootDir = rootDir; - this.outputPath = outputPath; - this.target = target; - } - - apply(compiler) { - compiler.hooks.emit.tapAsync( - 'ProcessPluginJsonPlugin', - (compilation, callback) => { - const pluginFilePath = resolve(this.rootDir, 'src', 'plugin.json'); - const distPluginFilePath = resolve(this.outputPath, 'plugin.json'); - if (this.target === WECHAT_MINIPROGRAM) { - copy(pluginFilePath, distPluginFilePath, () => { - callback(); - }); - } else if (this.target === MINIAPP) { - const pluginContent = transformPluginContent(pluginFilePath); - writeJSON(distPluginFilePath, pluginContent, { spaces: 2 }, () => { - callback(); - }); - } - } - ); - } -}; diff --git a/packages/build-plugin-rax-multi-pages/README.md b/packages/build-plugin-rax-multi-pages/README.md deleted file mode 100644 index 4e1c07914..000000000 --- a/packages/build-plugin-rax-multi-pages/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# build-plugin-multi-pages [![npm](https://img.shields.io/npm/v/build-plugin-multi-pages.svg)](https://www.npmjs.com/package/build-plugin-multi-pages) - -`build-scripts` plugin which make rax app generate multiple html files. - -## Warning! -Package "build-plugin-rax-multi-pages" has been deprecated. -Please use type: "mpa". example: - -```json -// app.json -{ - "plugins": [ - [ - "build-plugin-rax-app", - { - "targets": ["web"], - "type": "mpa" - } - ] - ] -} -``` - -See: [https://rax.js.org/docs/guide/rax-plugin-app](https://rax.js.org/docs/guide/rax-plugin-app) - -## Usage - -```json -{ - "plugins": [ - ["build-plugin-rax-app", {"targets": ["web"]}], - "build-plugin-rax-multi-pages" - ] -} -``` diff --git a/packages/build-plugin-rax-multi-pages/package.json b/packages/build-plugin-rax-multi-pages/package.json deleted file mode 100644 index c41455665..000000000 --- a/packages/build-plugin-rax-multi-pages/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "build-plugin-rax-multi-pages", - "version": "2.2.1", - "description": "rax app base plugins", - "license": "BSD-3-Clause", - "main": "src/index.js", - "peerDependencies": { - "build-plugin-rax-app": "^0.1.0" - }, - "dependencies": { - "chalk": "^2.4.2", - "rax-multi-pages-settings": "^0.1.0" - } -} diff --git a/packages/build-plugin-rax-multi-pages/src/index.js b/packages/build-plugin-rax-multi-pages/src/index.js deleted file mode 100644 index 59ac46d18..000000000 --- a/packages/build-plugin-rax-multi-pages/src/index.js +++ /dev/null @@ -1,60 +0,0 @@ -const chalk = require('chalk'); -const { setConfig, setDevLog } = require('rax-multi-pages-settings'); - - -module.exports = ({ context, onGetWebpackConfig, getValue, setValue, onHook }) => { - // Value appType("spa" or "mpa", default "spa") is a new feature to support MPA; - // See: https://github.com/raxjs/rax-scripts/issues/228 - const appType = getValue('appType'); - - if (appType) { - console.log(); - console.log(chalk.yellow('Warning! ')); - console.log(chalk.yellow('Package "build-plugin-rax-multi-pages" has been deprecated.')); - console.log(chalk.yellow('Please use type: "mpa". example: ')); - console.log(chalk.yellow(` -// build.json -{ - "plugins": [ - [ - "build-plugin-rax-app", - { - "targets": ["web"], - "type": "mpa" - } - ] - ] -} - -See: https://rax.js.org/docs/guide/rax-plugin-app - `)); - - // Use new MPA feature. - if (appType === 'mpa') { - return; - } - } else { - onHook('after.start.compile', ({ url, err, stats }) => { - setDevLog({ url, err, stats }); - }); - } - - - // Compatibility with old build-plugin-rax-multi-page - const { command } = context; - - const targets = getValue('targets'); - setValue('raxMpa', true); - - if (targets.includes('web')) { - onGetWebpackConfig('web', (config) => { - setConfig(config, context, targets, 'web'); - }); - } - - if (targets.includes('weex')) { - onGetWebpackConfig('weex', config => { - setConfig(config, context, targets, 'weex'); - }); - } -}; diff --git a/packages/build-plugin-rax-ssr/README.md b/packages/build-plugin-rax-ssr/README.md deleted file mode 100644 index b539e8b56..000000000 --- a/packages/build-plugin-rax-ssr/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# build-plugin-rax-ssr [![npm](https://img.shields.io/npm/v/build-plugin-rax-ssr.svg)](https://www.npmjs.com/package/build-plugin-rax-ssr) - - -`build-scripts` plugin which make rax app can server-side render pages - -## Usage - -```json -{ - "plugins": [ - ["build-plugin-rax-app", {"targets": ["web"]}], - "build-plugin-rax-ssr" - ] -} -``` diff --git a/packages/build-plugin-rax-ssr/package.json b/packages/build-plugin-rax-ssr/package.json deleted file mode 100644 index 123e45f19..000000000 --- a/packages/build-plugin-rax-ssr/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "build-plugin-rax-ssr", - "version": "3.0.5", - "description": "rax ssr plugins", - "license": "BSD-3-Clause", - "main": "src/index.js", - "dependencies": { - "address": "^1.0.1", - "chalk": "^4.0.0", - "error-stack-tracey": "^0.1.0", - "klaw-sync": "^6.0.0", - "null-loader": "^3.0.0", - "qs": "^6.8.0", - "rax-babel-config": "^0.1.0", - "rax-compile-config": "^0.2.0", - "rax-webpack-config": "^0.1.0" - } -} diff --git a/packages/build-plugin-rax-ssr/src/index.js b/packages/build-plugin-rax-ssr/src/index.js deleted file mode 100644 index 321419bf6..000000000 --- a/packages/build-plugin-rax-ssr/src/index.js +++ /dev/null @@ -1,44 +0,0 @@ -const path = require('path'); -const chalk = require('chalk'); -const getSSRBase = require('./ssr/getBase'); -const setSSRBuild = require('./ssr/setBuild'); -const setSSRDev = require('./ssr/setDev'); - -const setWebDev = require('./web/setDev'); - -// can‘t clone webpack chain object -module.exports = ({ onGetWebpackConfig, registerTask, context, getValue, setValue, onHook }) => { - process.env.RAX_SSR = 'true'; - - const { command, rootDir, userConfig = {} } = context; - const { outputDir } = userConfig; - - const ssrConfig = getSSRBase(context, getValue); - registerTask('ssr', ssrConfig); - - // Add ssr to the target list, so other plugins can get the right target info, eg. build-plugin-rax-compat-react - const targets = getValue('targets'); - targets.push('ssr'); - setValue('targets', targets); - - if (command === 'build') { - onGetWebpackConfig('ssr', (config) => { - setSSRBuild(config, context); - }); - } - - if (command === 'start') { - onGetWebpackConfig('ssr', (config) => { - setSSRDev(config, context); - }); - onGetWebpackConfig('web', (config) => { - setWebDev(config, context); - }); - } - - onHook('after.build.compile', ({ err, stats }) => { - console.log(chalk.green('[SSR] Bundle at:')); - console.log(' ', chalk.underline.white(path.resolve(rootDir, outputDir, 'node'))); - console.log(); - }); -}; diff --git a/packages/build-plugin-rax-ssr/src/ssr/entryLoader.js b/packages/build-plugin-rax-ssr/src/ssr/entryLoader.js deleted file mode 100644 index 3542bf5c3..000000000 --- a/packages/build-plugin-rax-ssr/src/ssr/entryLoader.js +++ /dev/null @@ -1,136 +0,0 @@ -const qs = require('qs'); -const fs = require('fs'); -const path = require('path'); - -const isWin = process.platform === 'win32'; - -/** - * Transform Windows-style paths, such as 'C:\Windows\system32' to 'C:/Windows/system32'. - * Because 'C:\Windows\system32' will be escaped to 'C:Windowssystem32' - * @param {*} p - */ -const formatPath = (p) => { - return isWin ? p.split(path.sep).join('/') : p; -}; - -module.exports = function() { - const query = typeof this.query === 'string' ? qs.parse(this.query.substr(1)) : this.query; - const { - absoluteDocumentPath, - absoluteShellPath, - pagePath, - styles = [], - scripts = [], - assetsProcessor - } = query; - - const absolutePagePath = formatPath(this.resourcePath); - const hasShell = fs.existsSync(absoluteShellPath); - const shellStr = hasShell ? `import Shell from '${formatPath(absoluteShellPath)}'` : 'const Shell = function (props) { return props.children };'; - - const renderHtmlFnc = ` - async function renderComponentToHTML(Component, ctx) { - - const shellData = await getInitialProps(Shell, ctx); - const pageData = await getInitialProps(Component, ctx); - const documentData = await getInitialProps(Document, ctx); - - const initialData = { - shellData, - pageData, - pagePath: '${pagePath}' - }; - - const contentElement = createElement(Shell, shellData, createElement(Component, pageData)); - - const initialHtml = renderer.renderToString(contentElement, { - defaultUnit: 'rpx' - }); - - // use let statement, because styles and scripts may be changed by assetsProcessor - let styles = ${JSON.stringify(styles)}; - let scripts = ${JSON.stringify(scripts)}; - - // process public path for different runtime env - ${assetsProcessor || ''} - - // This loader is executed after babel, so need to be tansformed to ES5. - const DocumentContextProvider = function() {}; - DocumentContextProvider.prototype.getChildContext = function() { - return { - __initialHtml: initialHtml, - __initialData: JSON.stringify(initialData), - __pagePath: '${pagePath}', - __styles: styles, - __scripts: scripts, - }; - }; - DocumentContextProvider.prototype.render = function() { - return createElement(Document, documentData); - }; - - const DocumentContextProviderElement = createElement(DocumentContextProvider); - - const html = '' + renderer.renderToString(DocumentContextProviderElement); - - return html; - } - `; - - const source = ` - import { createElement } from 'rax'; - import renderer from 'rax-server-renderer'; - - import Page from '${formatPath(absolutePagePath)}'; - import Document from '${formatPath(absoluteDocumentPath)}'; - ${shellStr} - - ${renderHtmlFnc} - - async function render(req, res) { - const html = await renderToHTML(req, res); - - res.setHeader('Content-Type', 'text/html; charset=utf-8'); - res.send(html); - } - - async function renderToHTML(req, res) { - const html = await renderComponentToHTML(Page, { - req, - res - }); - return html; - } - - // Handler for Midway FaaS and Koa - async function renderWithContext(ctx) { - const html = await renderComponentToHTML(Page, ctx); - - ctx.set('Content-Type', 'text/html; charset=utf-8'); - ctx.body = html; - } - - export { - render, - renderToHTML, - renderWithContext - }; - - export default render; - - async function getInitialProps(Component, ctx) { - if (!Component.getInitialProps) return null; - - const props = await Component.getInitialProps(ctx); - - if (!props || typeof props !== 'object') { - const message = '"getInitialProps()" should resolve to an object. But found "' + props + '" instead.'; - throw new Error(message); - } - - return props; - } - `; - - return source; -}; diff --git a/packages/build-plugin-rax-ssr/src/ssr/entryPlugin.js b/packages/build-plugin-rax-ssr/src/ssr/entryPlugin.js deleted file mode 100644 index e1e7b61fc..000000000 --- a/packages/build-plugin-rax-ssr/src/ssr/entryPlugin.js +++ /dev/null @@ -1,57 +0,0 @@ -const qs = require('qs'); - -/** - * An entry plugin which will set loader for entry before compile. - * - * Entry Loader for SSR need `publicPath` for assets path. - * `publicPath` may be changed by other plugin after SSR plugin. - * So the real `publicPath` can only get after all plugins have registed. - */ -class EntryPlugin { - constructor(options) { - this.options = options; - } - - /** - * @param {Compiler} compiler the compiler instance - * @returns {void} - */ - apply(compiler) { - const { - loader, - entries, - isMultiPages, - isInlineStyle, - absoluteDocumentPath, - absoluteShellPath, - assetsProcessor - } = this.options; - - const publicPath = compiler.options.output.publicPath; - - const entryConfig = {}; - - entries.forEach((entry) => { - const { - name, - sourcePath, - pagePath, - } = entry; - - const query = { - pagePath, - styles: isInlineStyle ? [] : isMultiPages ? [`${publicPath}web/${name}.css`] : [`${publicPath}web/index.css`], - scripts: isMultiPages ? [`${publicPath}web/${name}.js`] : [`${publicPath}web/index.js`], - absoluteDocumentPath, - absoluteShellPath, - assetsProcessor - }; - - entryConfig[name] = `${loader}?${qs.stringify(query)}!${sourcePath}`; - }); - - compiler.options.entry = entryConfig; - } -} - -module.exports = EntryPlugin; diff --git a/packages/build-plugin-rax-ssr/src/ssr/getBase.js b/packages/build-plugin-rax-ssr/src/ssr/getBase.js deleted file mode 100644 index 5e4397a2b..000000000 --- a/packages/build-plugin-rax-ssr/src/ssr/getBase.js +++ /dev/null @@ -1,65 +0,0 @@ -const path = require('path'); -const getWebpackBase = require('rax-webpack-config'); -const getBabelConfig = require('rax-babel-config'); -const getEntryName = require('./getEntryName'); -const EntryPlugin = require('./entryPlugin'); - -const EntryLoader = require.resolve('./entryLoader'); - -// Can‘t clone webpack chain object, so generate a new chain and reset config -module.exports = (context, getValue) => { - const { userConfig, rootDir } = context; - - const babelConfig = getBabelConfig({ - styleSheet: true, - jsxToHtml: true, - isNode: true - }); - - const config = getWebpackBase({ - ...context, - processBar: { - name: 'SSR' - }, - babelConfig: babelConfig, - }); - - config.target('node'); - - const { plugins, inlineStyle = true } = userConfig; - // build-plugin-rax-multi-pages is deprecated, but still need to be compatible. - const isMultiPages = getValue('appType') === 'mpa' || !!~plugins.indexOf('build-plugin-rax-multi-pages'); - const appJSON = require(path.resolve(rootDir, 'src/app.json')); - const entries = appJSON.routes.map((route) => { - return { - name: getEntryName(route.path), - sourcePath: path.join(rootDir, 'src', route.source), - pagePath: route.path, - }; - }); - - config.plugin('entryPlugin') - .use(EntryPlugin, [{ - entries, - loader: EntryLoader, - isMultiPages: isMultiPages, - isInlineStyle: inlineStyle, - absoluteDocumentPath: path.join(rootDir, 'src/document/index.jsx'), - absoluteShellPath: path.join(rootDir, 'src/shell/index.jsx'), - }]); - - config.output - .filename('node/[name].js') - .libraryTarget('commonjs2'); - - if (!inlineStyle) { - // there is no need to generate css file in node - config.module.rule('ignorecss') - .test(/\.(css|less|saas|scss)?$/) - .use('ignorecss') - .loader(require.resolve('null-loader')) - .end(); - } - - return config; -}; diff --git a/packages/build-plugin-rax-ssr/src/ssr/getEntryName.js b/packages/build-plugin-rax-ssr/src/ssr/getEntryName.js deleted file mode 100644 index 309cefc33..000000000 --- a/packages/build-plugin-rax-ssr/src/ssr/getEntryName.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Generate entryname by route.path - * Example: '/about/' -> 'about/index' - */ -module.exports = (path) => { - let entryName = 'index'; - - if (path && path !== '/') { - entryName = `${path.replace(/^\/|\/$/g, '')}/index`; - } - - return entryName; -}; diff --git a/packages/build-plugin-rax-ssr/src/ssr/setBuild.js b/packages/build-plugin-rax-ssr/src/ssr/setBuild.js deleted file mode 100644 index 7caea3ec0..000000000 --- a/packages/build-plugin-rax-ssr/src/ssr/setBuild.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = (config) => { - config.optimization.minimize(false); -}; diff --git a/packages/build-plugin-rax-ssr/src/ssr/setDev.js b/packages/build-plugin-rax-ssr/src/ssr/setDev.js deleted file mode 100644 index 3e99481fa..000000000 --- a/packages/build-plugin-rax-ssr/src/ssr/setDev.js +++ /dev/null @@ -1,63 +0,0 @@ - -const path = require('path'); -const Module = require('module'); -const { parse, print } = require('error-stack-tracey'); -const getEntryName = require('./getEntryName'); - -function exec(code, filename, filePath) { - const module = new Module(filename, this); - module.paths = Module._nodeModulePaths(filePath); - module.filename = filename; - module._compile(code, filename); - return module.exports; -} - -module.exports = (config, context) => { - const { rootDir } = context; - - config.mode('development'); - - const absoluteAppJSONPath = path.join(rootDir, 'src/app.json'); - const appJSON = require(absoluteAppJSONPath); - - const distDir = config.output.get('path'); - const filename = config.output.get('filename'); - const routes = appJSON.routes; - - routes.forEach((route) => { - const entryName = getEntryName(route.path); - route.entryName = entryName; - route.componentPath = path.join(distDir, filename.replace('[name]', entryName)); - }); - - // enable inline soucremap for get error stack - config.devtool('eval-cheap-source-map'); - - config.devServer.hot(false); - - // There can only be one `before` config, this config will overwrite `before` config in web plugin. - config.devServer.set('before', (app, devServer) => { - // outputFileSystem in devServer is MemoryFileSystem by defalut, but it can also be custom with other file systems. - const outputFs = devServer.compiler.compilers[0].outputFileSystem; - routes.forEach((route) => { - app.get(route.path, async function(req, res) { - const bundleContent = outputFs.readFileSync(route.componentPath, 'utf8'); - - process.once('unhandledRejection', async(error) => { - const errorStack = await parse(error, bundleContent); - print(error.message, errorStack); - }); - - try { - const mod = exec(bundleContent, route.componentPath, route.componentPath); - mod.render(req, res); - } catch (error) { - const errorStack = await parse(error, bundleContent); - print(error.message, errorStack); - } - }); - }); - }); - - return config; -}; diff --git a/packages/build-plugin-rax-ssr/src/web/setDev.js b/packages/build-plugin-rax-ssr/src/web/setDev.js deleted file mode 100644 index 782a86ad9..000000000 --- a/packages/build-plugin-rax-ssr/src/web/setDev.js +++ /dev/null @@ -1,15 +0,0 @@ -const { hmrClient } = require('rax-compile-config'); - -module.exports = (config) => { - const allEntries = config.entryPoints.entries(); - for (const entryName in allEntries) { - if (Object.prototype.hasOwnProperty.call(allEntries, entryName)) { - // remove hmrClient - config.entry(entryName).delete(hmrClient); - } - } - - config.devServer.delete('before'); - - return config; -}; diff --git a/packages/build-plugin-rax-theme/README.md b/packages/build-plugin-rax-theme/README.md deleted file mode 100644 index 055bb03ff..000000000 --- a/packages/build-plugin-rax-theme/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# build-plugin-rax-theme [![npm](https://img.shields.io/npm/v/build-plugin-rax-theme.svg)](https://www.npmjs.com/package/build-plugin-rax-theme) - - -## Usage - -```json -{ - "plugins": [ - ["build-plugin-rax-app", {"targets": ["web"]}], - "build-plugin-rax-theme" - ] -} -``` diff --git a/packages/build-plugin-rax-theme/package.json b/packages/build-plugin-rax-theme/package.json deleted file mode 100644 index aa111b250..000000000 --- a/packages/build-plugin-rax-theme/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "build-plugin-rax-theme", - "version": "0.1.0", - "description": "Switching project themes with CSS variables", - "license": "BSD-3-Clause", - "main": "src/index.js", - "repository": { - "type": "git" - }, - "dependencies": { - "less-loader": "^5.0.0", - "stylesheet-loader": "^0.8.0" - } -} \ No newline at end of file diff --git a/packages/build-plugin-rax-theme/src/index.js b/packages/build-plugin-rax-theme/src/index.js deleted file mode 100644 index 33f013c2c..000000000 --- a/packages/build-plugin-rax-theme/src/index.js +++ /dev/null @@ -1,26 +0,0 @@ -module.exports = (api) => { - const { onGetWebpackConfig } = api; - - onGetWebpackConfig((config) => { - config.module - .rule('css') - .test(/\.css?$/) - .use('css') - .loader(require.resolve('stylesheet-loader')) - .options({ - theme: true, - }); - - config.module - .rule('less') - .test(/\.less?$/) - .use('css') - .loader(require.resolve('stylesheet-loader')) - .end() - .use('less') - .loader(require.resolve('less-loader')) - .options({ - theme: true, - }); - }); -}; diff --git a/packages/create-rax/bin/create.js b/packages/create-rax/bin/create.js index 56f627e1f..e2e528965 100755 --- a/packages/create-rax/bin/create.js +++ b/packages/create-rax/bin/create.js @@ -10,7 +10,7 @@ const DEFAULT_REGISTRY = 'https://registry.npmjs.org'; function pingUrl(url) { return new Promise((resolve, reject) => { https - .get(url, res => { + .get(url, (res) => { const { statusCode } = res; if (statusCode === 200) { resolve(url); @@ -18,7 +18,7 @@ function pingUrl(url) { reject(new Error(`Http status is ${statusCode}`)); } }) - .on('error', err => { + .on('error', (err) => { reject(err); }); }); @@ -29,7 +29,7 @@ function checkRegistry() { } checkRegistry() - .then(registry => { + .then((registry) => { console.log('Current registry: ', registry); // Install rax-cli manually through fastest registry @@ -42,6 +42,6 @@ checkRegistry() stdio: 'inherit', }); }) - .catch(err => { + .catch((err) => { console.error(err); }); diff --git a/packages/error-stack-tracey/package.json b/packages/error-stack-tracey/package.json index 21fb460d1..7e9a046d3 100644 --- a/packages/error-stack-tracey/package.json +++ b/packages/error-stack-tracey/package.json @@ -2,7 +2,7 @@ "name": "error-stack-tracey", "version": "0.1.3", "description": "Trace error stack with sourcemap", - "main": "src/index.js", + "main": "lib/index.js", "license": "BSD-3-Clause", "repository": { "type": "git" diff --git a/packages/error-stack-tracey/src/index.js b/packages/error-stack-tracey/src/index.js index 0d930be5a..4294b7e83 100644 --- a/packages/error-stack-tracey/src/index.js +++ b/packages/error-stack-tracey/src/index.js @@ -34,7 +34,7 @@ async function parse(error, bundleContent) { } function print(message, stackFrame) { - const stackMessage = stackFrame.map(frame => { + const stackMessage = stackFrame.map((frame) => { if (frame.fromSourceMap) { return ` at ${frame.functionName} (${frame.source}:${frame.lineNumber}:${frame.columnNumber})`; } @@ -70,6 +70,7 @@ function getSourceMap(bundleContent) { return; } + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands const base64 = rawSourceMap.substr(base64Start + base64KeyWord.length); const sourceMapString = Buffer.from(base64, 'base64').toString('utf-8'); return JSON.parse(sourceMapString); diff --git a/packages/eslint-config-rax/README.md b/packages/eslint-config-rax/README.md deleted file mode 100644 index b54329524..000000000 --- a/packages/eslint-config-rax/README.md +++ /dev/null @@ -1,37 +0,0 @@ -## eslint-config-rax [![npm](https://img.shields.io/npm/v/eslint-config-rax.svg)](https://www.npmjs.com/package/eslint-config-rax) - -## Usage - -Shareable configs are designed to work with the `extends` feature of `.eslintrc` files. -You can learn more about -[Shareable Configs](http://eslint.org/docs/developer-guide/shareable-configs) on the -official ESLint website. - -Run the following command: - -```bash -npm install --save-dev eslint eslint-config-rax babel-eslint eslint-plugin-react eslint-plugin-import -``` - -Then, add this to your `.eslintrc.js` file: - -```js -// .eslintrc.js -module.exports = { - extends: ['rax'] -}; -``` - -*Note: We omitted the `eslint-config-` prefix since it is automatically assumed by ESLint.* - -If you use TypeScript, run the following command: - -```bash -npm install --save-dev eslint eslint-config-rax babel-eslint eslint-plugin-react eslint-plugin-import @typescript-eslint/parser @typescript-eslint/eslint-plugin -``` - -Then, Make sure you read about [the `--ext` command line option](https://eslint.org/docs/user-guide/command-line-interface#--ext). Example command line usage: - -``` -npx eslint --ext .js,.ts . -``` \ No newline at end of file diff --git a/packages/eslint-config-rax/index.js b/packages/eslint-config-rax/index.js deleted file mode 100644 index 91d06f045..000000000 --- a/packages/eslint-config-rax/index.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - extends: [ - './rules/globals', - './rules/base', - './rules/react', - './rules/typescript' - ].map(require.resolve), - rules: {}, -}; \ No newline at end of file diff --git a/packages/eslint-config-rax/package.json b/packages/eslint-config-rax/package.json deleted file mode 100644 index 4a606e7b1..000000000 --- a/packages/eslint-config-rax/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "eslint-config-rax", - "version": "0.1.0", - "description": "ESLint config for Rax", - "license": "BSD-3-Clause", - "main": "index.js", - "keywords": [ - "rax", - "eslint" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/raxjs/rax-scripts" - }, - "bugs": { - "url": "https://github.com/raxjs/rax-scripts/issues" - }, - "homepage": "https://github.com/raxjs/rax-scripts/tree/master/packages/eslint-config-rax#readme", - "peerDependencies": { - "babel-eslint": "^10.0.1", - "eslint": "^5.16.0 || ^6.7.2", - "eslint-plugin-import": "^2.18.2", - "eslint-plugin-react": "^7.15.1", - "eslint-plugin-module": "^0.1.0", - "@typescript-eslint/eslint-plugin": "^1.7.0", - "@typescript-eslint/parser": "^1.7.0" - } -} diff --git a/packages/eslint-config-rax/rules/base.js b/packages/eslint-config-rax/rules/base.js deleted file mode 100644 index 004c1332c..000000000 --- a/packages/eslint-config-rax/rules/base.js +++ /dev/null @@ -1,167 +0,0 @@ -module.exports = { - 'parser': 'babel-eslint', - 'env': { - 'browser': true, - 'node': true, - 'es6': true, - 'jest': true, - 'commonjs': true, - }, - 'plugins': [ - 'import', - 'module', - ], - 'parserOptions': { - 'sourceType': 'module', - 'ecmaVersion': 6, - 'ecmaFeatures': { - 'jsx': true, - 'generators': true, - 'experimentalObjectRestSpread': true, - }, - }, - 'settings': {}, - 'rules': { - /** - * ES6 - */ - 'no-const-assign': 'error', - 'no-class-assign': 'error', - 'no-dupe-class-members': 'error', - 'rest-spread-spacing': 'error', - 'no-duplicate-imports': 'error', - 'no-useless-rename': 'error', - 'arrow-spacing': 'error', - 'no-useless-computed-key': 'error', - 'template-curly-spacing': 'error', - 'generator-star-spacing': ['error', {'before': false, 'after': true}], - 'yield-star-spacing': ['error', {'before': false, 'after': true}], - 'no-undef': 'error', - 'dot-notation': ['error', { - 'allowKeywords': true, - }], - 'no-extend-native': 'error', - 'no-native-reassign': 'error', - 'no-constant-condition': ['error', { - 'checkLoops': false, - }], - 'no-caller': 'error', - 'no-return-assign': 'off', - 'no-loop-func': 'off', - 'strict': ['off', 'global'], - 'global-strict': ['off', 'always'], - 'no-extra-strict': 'off', - 'no-shadow': 'off', - 'no-unused-vars': ['off', { - 'vars': 'local', - 'args': 'after-used', - 'varsIgnorePattern': 'createElement', - }], - 'no-unused-expressions': 'off', - 'no-use-before-define': 'off', - 'no-array-constructor': 'off', - 'yoda': 'off', - 'eqeqeq': 'off', - 'no-new': 'off', - 'consistent-return': 'off', - 'prefer-const': 'off', - /** - * Node.js - */ - 'no-catch-shadow': 'error', - 'quotes': ['error', 'single', 'avoid-escape'], - 'brace-style': ['error', '1tbs', { - 'allowSingleLine': false, - }], - 'comma-spacing': ['error', { - 'before': false, - 'after': true, - }], - 'comma-style': ['error', 'last'], - 'new-cap': ['error', { - 'newIsCap': true, - 'capIsNew': false - }], - 'key-spacing': ['error', { - 'beforeColon': false, - 'afterColon': true, - }], - 'no-mixed-spaces-and-tabs': 'error', - 'no-multi-spaces': 'error', - 'no-multiple-empty-lines': 'error', - 'no-new-object': 'error', - 'no-spaced-func': 'error', - 'no-tabs': 'error', - 'no-trailing-spaces': 'error', - 'no-extra-parens': ['error', 'all', { ignoreJSX: 'all' }], - 'padded-blocks': ['error', 'never'], - 'semi': 'error', - 'semi-spacing': 'error', - 'keyword-spacing': 'error', - 'space-before-blocks': 'error', - 'space-before-function-paren': ['error', 'never'], - 'space-infix-ops': 'error', - 'spaced-comment': ['error', 'always', { - 'line': { - 'markers': ['/'], - 'exceptions': ['-', '+'], - }, - 'block': { - 'markers': ['!'], - 'exceptions': ['*'], - 'balanced': true, - }, - }], - 'no-console': 'off', - 'no-new-require': 'off', - 'no-mixed-requires': ['off', false], - 'no-path-concat': 'off', - 'handle-callback-err': 'off', - 'eol-last': 'off', - 'func-names': 'off', - 'no-empty': 'off', - 'indent': ['error', 2, { - 'SwitchCase': 1, - }], - 'camelcase': ['off', { - 'properties': 'always', - }], - - /** - * Import - */ - 'import/newline-after-import': 'error', - 'import/no-duplicates': 'error', - 'import/no-extraneous-dependencies': [ - 'error', - { - 'peerDependencies': true, - 'devDependencies': [ - '**/scripts/*.js', - '**/scripts/**/*.js', - '**/__tests__/*.js', - '**/__tests__/**/*.js', - '**/*.config.js', - '**/config/*.js', - '**/*.conf.js', - '**/tests/*.test.js', - '**/demo/**' - ], - }, - ], - 'module/no-implicit-dependencies': ['error', { - 'peerDependencies': true, - 'devDependencies': [ - '**/scripts/*.js', - '**/scripts/**/*.js', - '**/__tests__/*.js', - '**/__tests__/**/*.js', - '**/*.config.js', - '**/config/*.js', - '**/*.conf.js', - '**/tests/*.test.js', - '**/demo/**' - ] - }] - }, -}; diff --git a/packages/eslint-config-rax/rules/globals.js b/packages/eslint-config-rax/rules/globals.js deleted file mode 100644 index 4c40509e3..000000000 --- a/packages/eslint-config-rax/rules/globals.js +++ /dev/null @@ -1,26 +0,0 @@ -module.exports = { - 'globals': { - // Apache Weex - '__weex_data__': 'readonly', - '__weex_options__': 'readonly', - '__weex_downgrade__': 'readonly', - '__weex_define__': 'readonly', - '__weex_require__': 'readonly', - 'WXEnvironment': 'readonly', - 'weex': 'readonly', - // Alibaba MiniApp - 'my': 'readonly', - // WeChat MiniProgram - 'wx': 'readonly', - // MiniApp - 'Page': 'readonly', - 'Component': 'readonly', - // Web - 'webkitRequestAnimationFrame': 'readonly', - 'webkitCancelAnimationFrame': 'readonly', - // React - 'React': 'readonly', - // Rax - 'Rax': 'readonly' - }, -}; diff --git a/packages/eslint-config-rax/rules/react.js b/packages/eslint-config-rax/rules/react.js deleted file mode 100644 index ab955c3c0..000000000 --- a/packages/eslint-config-rax/rules/react.js +++ /dev/null @@ -1,54 +0,0 @@ -module.exports = { - 'plugins': [ - 'react', - ], - 'settings': { - 'react': { - 'pragma': 'createElement', // Pragma to use, default to "React" - 'pragmaFrag': 'Fragment', - }, - }, - 'rules': { - /** - * React & JSX - */ - 'jsx-quotes': ['error', 'prefer-double'], - 'react/jsx-no-bind': ['error', { - 'allowArrowFunctions': true, - }], - 'react/prefer-es6-class': 'error', - 'react/jsx-curly-spacing': 'error', - 'react/jsx-indent-props': ['error', 2], // 2 spaces indentation - 'react/jsx-no-duplicate-props': 'error', - 'react/jsx-no-undef': 'error', - 'react/jsx-tag-spacing': 'error', - 'react/jsx-no-comment-textnodes': 'error', - 'react/jsx-equals-spacing': 'error', - 'react/jsx-uses-react': 'error', - 'react/jsx-uses-vars': 'error', - 'react/no-is-mounted': 'error', - 'react/no-children-prop': 'error', - 'react/no-did-mount-set-state': 'error', - 'react/no-did-update-set-state': 'error', - 'react/style-prop-object': 'error', - 'react/react-in-jsx-scope': 'error', - // Avoid throw lint error like - 'react/self-closing-comp': ['error', { - 'html': false - }], - 'react/display-name': 'off', - 'react/jsx-boolean-value': ['off', 'always'], - 'react/jsx-handler-names': 'off', - 'react/no-unknown-property': 'off', - 'react/sort-comp': ['off', { - 'order': [ - 'lifecycle', - '/^on.+$/', - '/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/', - 'everything-else', - '/^render.+$/', - 'render', - ], - }], - }, -}; diff --git a/packages/eslint-config-rax/rules/typescript.js b/packages/eslint-config-rax/rules/typescript.js deleted file mode 100644 index ecbaa0ba8..000000000 --- a/packages/eslint-config-rax/rules/typescript.js +++ /dev/null @@ -1,85 +0,0 @@ -module.exports = { - 'overrides': [ - { - 'files': ['**/*.ts?(x)'], - 'parser': '@typescript-eslint/parser', - 'parserOptions': { - 'sourceType': 'module', - 'ecmaFeatures': { - 'jsx': true, - }, - }, - 'plugins': ['@typescript-eslint'], - 'rules': { - /** - * Indent is replaced by two Spaces - * @reason Conventional convention - */ - 'indent': 'off', - '@typescript-eslint/indent': [ - 'error', - 2, - { - 'SwitchCase': 1, - 'flatTernaryExpressions': true, - }, - ], - - /** - * use of parentheses to only where they are necessary - * @reason If set `all` as `(window as any).xxx` will trow error - */ - 'no-extra-parens': ['error', 'functions'], - - /** - * The return value of the function must be the same as the declared type - * @reason Typescript compilation check is enough - */ - '@typescript-eslint/explicit-function-return-type': 'off', - - /** - * Disallow usage of the `any` type - * @reason It is difficult to avoid not using `any` type - */ - '@typescript-eslint/no-explicit-any': 'off', - - /** - * Disallow the use of custom TypeScript modules and namespaces - * @reason For easy to use global lib - */ - '@typescript-eslint/no-namespace': 'off', - - - /** - * Recommended rules - * Basic rules follow here: https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules - */ - '@typescript-eslint/adjacent-overload-signatures': 'error', - '@typescript-eslint/array-type': 'error', - '@typescript-eslint/ban-types': 'error', - '@typescript-eslint/camelcase': ['error', { - 'allow': ['\__.*\__'] - }], - '@typescript-eslint/class-name-casing': 'error', - '@typescript-eslint/explicit-member-accessibility': 'error', - '@typescript-eslint/interface-name-prefix': 'error', - '@typescript-eslint/member-delimiter-style': 'error', - '@typescript-eslint/no-angle-bracket-type-assertion': 'error', - '@typescript-eslint/no-array-constructor': 'error', - '@typescript-eslint/no-empty-interface': 'error', - '@typescript-eslint/no-inferrable-types': 'error', - '@typescript-eslint/no-misused-new': 'error', - '@typescript-eslint/no-non-null-assertion': 'error', - '@typescript-eslint/no-object-literal-type-assertion': 'error', - '@typescript-eslint/no-parameter-properties': 'error', - '@typescript-eslint/no-triple-slash-reference': 'error', - '@typescript-eslint/no-use-before-define': 'error', - '@typescript-eslint/no-var-requires': 'error', - '@typescript-eslint/prefer-interface': 'error', - '@typescript-eslint/prefer-namespace-keyword': 'error', - '@typescript-eslint/type-annotation-spacing': 'error', - '@typescript-eslint/no-unused-vars': 'off', - }, - } - ] -}; diff --git a/packages/eslint-plugin-module/README.md b/packages/eslint-plugin-module/README.md deleted file mode 100644 index d776946a1..000000000 --- a/packages/eslint-plugin-module/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# eslint-plugin-module - -ESLint plugins for module. - -```bash -npm install eslint-plugin-moudle -g -``` - -## rules - -### no-extraneous-dependencies - -Forbid the import of external modules that are not declared in the `package.json`'s `dependencies`, `devDependencies`, `optionalDependencies`, `peerDependencies`, or `bundledDependencies`. -The closest parent `package.json` will be used. If no `package.json` is found, the rule will not lint anything. This behaviour can be changed with the rule option `packageDir`. - -This rule is inspired by [import/no-extraneous-dependencies](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md) and TSLint rule [no-implicit-dependencies](https://palantir.github.io/tslint/rules/no-implicit-dependencies/). - -The difference between [import/no-extraneous-dependencies](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md), is that modules don't have to be installed for this rule to work. - -This rule supports the following options: - -`devDependencies`: If set to `false`, then the rule will show an error when `devDependencies` are imported. Defaults to `true`. - -`optionalDependencies`: If set to `false`, then the rule will show an error when `optionalDependencies` are imported. Defaults to `true`. - -`peerDependencies`: If set to `false`, then the rule will show an error when `peerDependencies` are imported. Defaults to `false`. - -`bundledDependencies`: If set to `false`, then the rule will show an error when `bundledDependencies` are imported. Defaults to `true`. - -`whitelist`: Whitelisted modules can to be added to skip checking their existence in package.json. - -You can set the options like this: - -```js -"module/no-extraneous-dependencies": ["error", {"devDependencies": false, "optionalDependencies": false, "peerDependencies": false}] -``` - -You can also use an array of globs instead of literal booleans: - -```js -"module/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.js", "**/*.spec.js"]}] -``` - -You can set the whitelist modules like this: -```js -"module/no-extraneous-dependencies": ["error", {"devDependencies": ["@components"]}] -``` diff --git a/packages/eslint-plugin-module/package.json b/packages/eslint-plugin-module/package.json deleted file mode 100644 index 088a81ac5..000000000 --- a/packages/eslint-plugin-module/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "eslint-plugin-module", - "version": "0.1.0", - "description": "The ESLint configs for module.", - "license": "BSD-3-Clause", - "main": "src/index.js", - "keywords": [ - "module", - "eslint" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/raxjs/rax-scripts" - }, - "bugs": { - "url": "https://github.com/raxjs/rax-scripts/issues" - }, - "homepage": "https://github.com/raxjs/rax-scripts/tree/master/packages/eslint-plugin-module#readme", - "peerDependencies": { - "eslint": "^5.16.0 || ^6.7.2" - }, - "dependencies": { - "builtin-modules": "^3.1.0", - "minimatch": "^3.0.4", - "read-pkg-up": "^7.0.1" - } -} diff --git a/packages/eslint-plugin-module/src/index.js b/packages/eslint-plugin-module/src/index.js deleted file mode 100644 index a47ca4b21..000000000 --- a/packages/eslint-plugin-module/src/index.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -module.exports = { - rules: { - 'no-implicit-dependencies': require('./rules/no-implicit-dependencies') - } -}; diff --git a/packages/eslint-plugin-module/src/rules/no-implicit-dependencies.js b/packages/eslint-plugin-module/src/rules/no-implicit-dependencies.js deleted file mode 100644 index fd990ada1..000000000 --- a/packages/eslint-plugin-module/src/rules/no-implicit-dependencies.js +++ /dev/null @@ -1,259 +0,0 @@ -/** - * Disallows importing modules that are not listed as dependency in the project’s package.json - * This rule is inspired by: - * import/no-extraneous-dependencies: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md - * TSLint rule no-implicit-dependencies: https://palantir.github.io/tslint/rules/no-implicit-dependencies/ - */ -const path = require('path'); -const fs = require('fs'); -const builtins = require('builtin-modules'); -const readPkgUp = require('read-pkg-up'); -const minimatch = require('minimatch'); - -function isStaticRequire(node) { - return node && - node.callee && - node.callee.type === 'Identifier' && - node.callee.name === 'require' && - node.arguments.length === 1 && - node.arguments[0].type === 'Literal' && - typeof node.arguments[0].value === 'string'; -} - -function hasKeys(obj = {}) { - return Object.keys(obj).length > 0; -} - -function arrayOrKeys(arrayOrObject) { - return Array.isArray(arrayOrObject) ? arrayOrObject : Object.keys(arrayOrObject); -} - -function extractDepFields(pkg = {}) { - return { - dependencies: pkg.dependencies || {}, - devDependencies: pkg.devDependencies || {}, - optionalDependencies: pkg.optionalDependencies || {}, - peerDependencies: pkg.peerDependencies || {}, - // BundledDeps should be in the form of an array, but object notation is also supported by - // `npm`, so we convert it to an array if it is an object - bundledDependencies: arrayOrKeys(pkg.bundleDependencies || pkg.bundledDependencies || []), - }; -} - -function getDependencies(context, packageDir) { - let paths = []; - try { - const packageContent = { - dependencies: {}, - devDependencies: {}, - optionalDependencies: {}, - peerDependencies: {}, - bundledDependencies: [], - }; - - if (packageDir && packageDir.length > 0) { - if (!Array.isArray(packageDir)) { - paths = [path.resolve(packageDir)]; - } else { - paths = packageDir.map(dir => path.resolve(dir)); - } - } - - if (paths.length > 0) { - // use rule config to find package.json - paths.forEach(dir => { - const _packageContent = extractDepFields( - JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')) - ); - Object.keys(packageContent).forEach(depsKey => - Object.assign(packageContent[depsKey], _packageContent[depsKey]) - ); - }); - } else { - // use closest package.json - Object.assign( - packageContent, - extractDepFields( - readPkgUp.sync({cwd: context.getFilename(), normalize: false}).packageJson - ) - ); - } - - if (![ - packageContent.dependencies, - packageContent.devDependencies, - packageContent.optionalDependencies, - packageContent.peerDependencies, - packageContent.bundledDependencies, - ].some(hasKeys)) { - return null; - } - - return packageContent; - } catch (e) { - if (paths.length > 0 && e.code === 'ENOENT') { - context.report({ - message: 'The package.json file could not be found.', - loc: { line: 0, column: 0 }, - }); - } - if (e.name === 'JSONError' || e instanceof SyntaxError) { - context.report({ - message: 'The package.json file could not be parsed: ' + e.message, - loc: { line: 0, column: 0 }, - }); - } - - return null; - } -} - -function missingErrorMessage(packageName) { - return `'${packageName}' should be listed in the project's dependencies. ` + - `Run 'npm i -S ${packageName}' to add it`; -} - -function devDepErrorMessage(packageName) { - return `'${packageName}' should be listed in the project's dependencies, not devDependencies.`; -} - -function optDepErrorMessage(packageName) { - return `'${packageName}' should be listed in the project's dependencies, ` + - 'not optionalDependencies.'; -} - -function reportIfMissing(context, deps, depsOptions, node, name) { - // Do not report when importing types - if (node.importKind === 'type') { - return; - } - - if (pathIsRelative(name)) { - return; - } - - const options = context.options[0] || {}; - const whitelist = options.whitelist || []; - const packageName = getPackageName(name, whitelist); - - if (whitelist.includes(packageName)) { - return; - } - - if (builtins.includes(packageName)) { - return; - } - - const isInDeps = deps.dependencies[packageName] !== undefined; - const isInDevDeps = deps.devDependencies[packageName] !== undefined; - const isInOptDeps = deps.optionalDependencies[packageName] !== undefined; - const isInPeerDeps = deps.peerDependencies[packageName] !== undefined; - const isInBundledDeps = deps.bundledDependencies.indexOf(packageName) !== -1; - - if (isInDeps || - depsOptions.allowDevDeps && isInDevDeps || - depsOptions.allowPeerDeps && isInPeerDeps || - depsOptions.allowOptDeps && isInOptDeps || - depsOptions.allowBundledDeps && isInBundledDeps - ) { - return; - } - - if (isInDevDeps && !depsOptions.allowDevDeps) { - context.report(node, devDepErrorMessage(packageName)); - return; - } - - if (isInOptDeps && !depsOptions.allowOptDeps) { - context.report(node, optDepErrorMessage(packageName)); - return; - } - - context.report(node, missingErrorMessage(packageName)); -} - -function getPackageName(name, whitelist) { - var parts = name.split(/\//g); - if (name[0] !== '@' || whitelist.includes(parts[0])) { - return parts[0]; - } - if (whitelist.includes(name)) { - return name; - } - return parts[0] + '/' + parts[1]; -} - -function testConfig(config, filename) { - // Simplest configuration first, either a boolean or nothing. - if (typeof config === 'boolean' || typeof config === 'undefined') { - return config; - } - // Array of globs. - return config.some(c => - minimatch(filename, c) || - minimatch(filename, path.join(process.cwd(), c)) - ); -} - -/** - * Determines whether a path starts with a relative path component (i.e. `.` or `..`). - */ -function pathIsRelative(path) { - return /^\.\.?($|[\\/])/.test(path); -} - -module.exports = { - meta: { - type: 'problem', - schema: [ - { - 'type': 'object', - 'properties': { - 'devDependencies': { 'type': ['boolean', 'array'] }, - 'optionalDependencies': { 'type': ['boolean', 'array'] }, - 'peerDependencies': { 'type': ['boolean', 'array'] }, - 'bundledDependencies': { 'type': ['boolean', 'array'] }, - 'packageDir': { 'type': ['string', 'array'] }, - 'whitelist': {'type': 'array'} - }, - 'additionalProperties': false, - }, - ], - }, - - create: function(context) { - const options = context.options[0] || {}; - const filename = context.getFilename(); - const deps = getDependencies(context, options.packageDir) || extractDepFields({}); - - const depsOptions = { - allowDevDeps: testConfig(options.devDependencies, filename) !== false, - allowOptDeps: testConfig(options.optionalDependencies, filename) !== false, - allowPeerDeps: testConfig(options.peerDependencies, filename) !== false, - allowBundledDeps: testConfig(options.bundledDependencies, filename) !== false, - }; - - return { - ImportDeclaration: function(node) { - if (node.source) { - reportIfMissing(context, deps, depsOptions, node, node.source.value); - } - }, - ExportNamedDeclaration: function(node) { - if (node.source) { - reportIfMissing(context, deps, depsOptions, node, node.source.value); - } - }, - ExportAllDeclaration: function(node) { - if (node.source) { - reportIfMissing(context, deps, depsOptions, node, node.source.value); - } - }, - CallExpression: function handleRequires(node) { - if (isStaticRequire(node)) { - reportIfMissing(context, deps, depsOptions, node, node.arguments[0].value); - } - }, - }; - }, -}; diff --git a/packages/image-source-loader/README.md b/packages/image-source-loader/README.md deleted file mode 100644 index b90cf8b1f..000000000 --- a/packages/image-source-loader/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# image source loader for webpack - -A source is an object contains: base64 uri, width and height of a image. eg: `{ uri: 'data:image/png;base64, iVBxxxx...', width: 2, height: 3 }` - -If your looking for a loader that simple encodes as base64 try [base64-loader](https://github.com/antelle/base64-loader) - -## Installation - -`npm install image-source-loader` - -## Usage - -``` javascript -const source = require("image-source!./1x1.png"); - -// source => { -// uri: "data:image/png;base64,iVBORw0KGgoAAAANS...", -// width: 1, -// height: 1 -// } -``` - -[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html) - -## Support - -See ./mimes.json for currently supported extensions/mimes. -Create a Pull Request if you need more added. diff --git a/packages/image-source-loader/mimes.json b/packages/image-source-loader/mimes.json deleted file mode 100644 index 634733880..000000000 --- a/packages/image-source-loader/mimes.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "bmp": "image/x-ms-bmp", - "cgm": "image/cgm", - "g3": "image/g3fax", - "gif": "image/gif", - "ief": "image/ief", - "jpeg": "image/jpeg", - "jpg": "image/jpeg", - "jpe": "image/jpeg", - "ktx": "image/ktx", - "png": "image/png", - "btif": "image/prs.btif", - "sgi": "image/sgi", - "svg": "image/svg+xml", - "svgz": "image/svg+xml", - "tiff": "image/tiff", - "tif": "image/tiff", - "psd": "image/vnd.adobe.photoshop", - "uvi": "image/vnd.dece.graphic", - "uvvi": "image/vnd.dece.graphic", - "uvg": "image/vnd.dece.graphic", - "uvvg": "image/vnd.dece.graphic", - "djvu": "image/vnd.djvu", - "djv": "image/vnd.djvu", - "sub": "image/vnd.dvb.subtitle", - "dwg": "image/vnd.dwg", - "dxf": "image/vnd.dxf", - "fbs": "image/vnd.fastbidsheet", - "fpx": "image/vnd.fpx", - "fst": "image/vnd.fst", - "mmr": "image/vnd.fujixerox.edmics-mmr", - "rlc": "image/vnd.fujixerox.edmics-rlc", - "mdi": "image/vnd.ms-modi", - "wdp": "image/vnd.ms-photo", - "npx": "image/vnd.net-fpx", - "wbmp": "image/vnd.wap.wbmp", - "xif": "image/vnd.xiff", - "webp": "image/webp", - "3ds": "image/x-3ds", - "ras": "image/x-cmu-raster", - "cmx": "image/x-cmx", - "fh": "image/x-freehand", - "fhc": "image/x-freehand", - "fh4": "image/x-freehand", - "fh5": "image/x-freehand", - "fh7": "image/x-freehand", - "ico": "image/x-icon", - "jng": "image/x-jng", - "sid": "image/x-mrsid-image", - "pcx": "image/x-pcx", - "pic": "image/x-pict", - "pct": "image/x-pict", - "pnm": "image/x-portable-anymap", - "pbm": "image/x-portable-bitmap", - "pgm": "image/x-portable-graymap", - "ppm": "image/x-portable-pixmap", - "rgb": "image/x-rgb", - "tga": "image/x-tga", - "xbm": "image/x-xbitmap", - "xpm": "image/x-xpixmap", - "xwd": "image/x-xwindowdump" -} diff --git a/packages/image-source-loader/package.json b/packages/image-source-loader/package.json deleted file mode 100644 index fa40edc92..000000000 --- a/packages/image-source-loader/package.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "image-source-loader", - "version": "0.6.5", - "description": "Image source loader for webpack", - "license": "MIT", - "repository": { - "type": "git", - "url": "https://github.com/raxjs/rax-scripts.git" - }, - "engines": { - "npm": ">=3.0.0" - }, - "keywords": [ - "base64", - "image", - "webpack", - "loader", - "img", - "src" - ], - "main": "lib/index.js", - "dependencies": { - "image-size": "^0.5.1" - } -} diff --git a/packages/image-source-loader/src/__mocks__/one-pixel-png.js b/packages/image-source-loader/src/__mocks__/one-pixel-png.js deleted file mode 100644 index 6f981560f..000000000 --- a/packages/image-source-loader/src/__mocks__/one-pixel-png.js +++ /dev/null @@ -1,2 +0,0 @@ -const onePixelPng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1, 0, 0, 0, 1, 8, 2, 0, 0, 0, 144, 119, 83, 222, 0, 0, 0, 1, 115, 82, 71, 66, 0, 174, 206, 28, 233, 0, 0, 0, 4, 103, 65, 77, 65, 0, 0, 177, 143, 11, 252, 97, 5, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, 195, 0, 0, 14, 195, 1, 199, 111, 168, 100, 0, 0, 0, 12, 73, 68, 65, 84, 24, 87, 99, 248, 255, 255, 63, 0, 5, 254, 2, 254, 167, 53, 129, 132, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130]; -module.exports = new Buffer(onePixelPng); diff --git a/packages/image-source-loader/src/__tests__/index.js b/packages/image-source-loader/src/__tests__/index.js deleted file mode 100644 index 4bd10bf20..000000000 --- a/packages/image-source-loader/src/__tests__/index.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict'; -const imageSourceLoader = require('../index'); -/* eslint-disable */ -const onePixelPng = require('one-pixel-png'); -/* eslint-enable */ -describe('test image source loader', () => { - it('output the base64 string', () => { - const thisObj = { resourcePath: 'filename.png' }; - const aBase64String = 'SGVsbG8gV29ybGQ='; - const result = imageSourceLoader.call(thisObj, new Buffer(aBase64String, 'base64')); - expect(result).toEqual(expect.stringMatching(aBase64String)); - }); - - it('should set extension for jpg', () => { - const thisObj = { resourcePath: 'filename.jpg' }; - const result = imageSourceLoader.call(thisObj, new Buffer('')); - - expect(result).toEqual(expect.stringMatching('image/jpeg')); - }); - - it('should set extension for png', () => { - const thisObj = { resourcePath: 'filename.png' }; - const result = imageSourceLoader.call(thisObj, new Buffer('')); - - expect(result).toEqual(expect.stringMatching('image/png')); - }); - - it('should throw an error on unknown file extension', () => { - const thisObj = { resourcePath: 'filename.bad' }; - - expect(imageSourceLoader.bind(thisObj, new Buffer(''))).toThrow(Error); - }); - - it('output the base64 of the test image', () => { - const testImage = onePixelPng; - const testImageBase64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAMSURBVBhXY/j//z8ABf4C/qc1gYQAAAAASUVORK5CYII='; // eslint-disable-line max-len - - const thisObj = { resourcePath: 'filename.png' }; - - const result = imageSourceLoader.call(thisObj, testImage); - expect(result).toEqual(expect.stringMatching(testImageBase64)); - expect(result).toEqual(expect.stringMatching('width: 1')); - expect(result).toEqual(expect.stringMatching('height: 1')); - }); - - it('case insensitive extension matching', () => { - const testImage = onePixelPng; - const testImageBase64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAMSURBVBhXY/j//z8ABf4C/qc1gYQAAAAASUVORK5CYII='; // eslint-disable-line max-len - - const thisObj = { resourcePath: 'filename.pNG' }; - - const result = imageSourceLoader.call(thisObj, testImage); - - expect(result).toEqual(expect.stringMatching(testImageBase64)); - expect(result).toEqual(expect.stringMatching('width: 1')); - expect(result).toEqual(expect.stringMatching('height: 1')); - }); -}); diff --git a/packages/image-source-loader/src/index.js b/packages/image-source-loader/src/index.js deleted file mode 100644 index 17dde7c96..000000000 --- a/packages/image-source-loader/src/index.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -const imageSize = require('image-size'); -const mimes = require('../mimes.json'); - -function getMime(path) { - const extension = path.split('.').pop().toLowerCase(); - const mime = mimes[extension]; - if (!mime) { - throw new Error('Unsupported type of image of extension ' + extension + ': ' + path); - } - return mime; -} - -module.exports = function base64ImageLoader(content) { - this.cacheable && this.cacheable(); - const dimensions = {}; - try { - const _dimensions = imageSize(content); - Object.assign(dimensions, _dimensions); - } catch (err) {} - return `module.exports = { - uri: "data:${getMime(this.resourcePath)};base64,${content.toString('base64')}", - width: ${dimensions.width || 'undefined'}, - height: ${dimensions.height || 'undefined'} - }`; -}; -module.exports.raw = true; diff --git a/packages/jsx2mp-cli/.gitignore b/packages/jsx2mp-cli/.gitignore deleted file mode 100644 index 33a9488b1..000000000 --- a/packages/jsx2mp-cli/.gitignore +++ /dev/null @@ -1 +0,0 @@ -example diff --git a/packages/jsx2mp-cli/.npmignore b/packages/jsx2mp-cli/.npmignore deleted file mode 100644 index dbb65422e..000000000 --- a/packages/jsx2mp-cli/.npmignore +++ /dev/null @@ -1,7 +0,0 @@ -coverage -.idea -example -__tests__ -demo -es/* -lib/* diff --git a/packages/jsx2mp-cli/README.md b/packages/jsx2mp-cli/README.md deleted file mode 100644 index 283f1b1ce..000000000 --- a/packages/jsx2mp-cli/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# jsx2mp-cli - -A cli tool to transform Rax JSX based project to MiniApp. - -## Usage as cli tool. - -1. Create a miniapp based project using rax-cli. - ```bash - rax init myApp - ``` - -2. Install jsx2mp-cli - ```bash - npm install jsx2mp-cli -g - ``` - -3. Transform your project. - ```bash - cd myApp - jsx2mp start - ``` - The tool will keep watching your source files before being interpreted by `Ctrl + C`. - -4. Use `小程序开发工具` to open `dist` directory under your project path. - -> You can also use rax-scripts to build miniapp, which intergrate the jsx2mp-cli. - -## Integration Testing - -As project-based integration testing, the test includes the following cases: - -1. import static assets diff --git a/packages/jsx2mp-cli/__tests__/component.js b/packages/jsx2mp-cli/__tests__/component.js deleted file mode 100644 index 0b3f56dff..000000000 --- a/packages/jsx2mp-cli/__tests__/component.js +++ /dev/null @@ -1,56 +0,0 @@ -const { readFileSync } = require('fs'); -const { join } = require('path'); -const { execSync } = require('child_process'); - -const compileCommand = '../bin/jsx2mp.js build --type component --entry ./component --dist ./dist --turn-off-check-update'; - -let jsonContent, jsContent, axmlContent; - -const currentCwd = process.cwd(); -const cwd = currentCwd.indexOf('jsx2mp-cli') === -1 ? join(currentCwd, 'packages/jsx2mp-cli') : currentCwd; - -const execSyncWithCwd = (command) => { - execSync(command, { - cwd - }); -}; - -beforeAll(() => { - execSyncWithCwd(`cd demo && npm install --no-package-lock && ${compileCommand}`); - - // read from file and get compiled result - jsonContent = readFileSync(join(cwd, 'demo/dist/component.json'), {encoding: 'utf8'}); - jsContent = readFileSync(join(cwd, 'demo/dist/component.js'), {encoding: 'utf8'}); - axmlContent = readFileSync(join(cwd, 'demo/dist/component.axml'), {encoding: 'utf8'}); -}); - -afterAll(() => { - execSyncWithCwd('rm -rf demo/dist'); -}); - -describe('Component compiled result', () => { - it('should return correct axml', () => { - expect(axmlContent).toEqual( - ` - Hello World! - `); - }); - - it('should return correct js', () => { - expect(jsContent).toEqual( - '"use strict";var _jsx2mpRuntime=require("./npm/jsx2mp-runtime"),_index=require("./npm/rax-view/lib/index.js"),img="./assets/rax.png",a=0,b=1;function Index(){(0,_index.custom)(),this._updateChildProps("0",{source:{uri:img},c:a&&b,d:img?a:b}),this._updateData({_d0:img,_d1:a,_d2:b}),this._updateMethods({})}var __def__=Index;Component((0,_jsx2mpRuntime.createComponent)(__def__));' - ); - }); - - it('should return correct json', () => { - expect(jsonContent).toEqual( - `{ - "component": true, - "usingComponents": { - "rax-image": "./npm/rax-image/lib/miniapp/index" - } -} -` - ); - }); -}); diff --git a/packages/jsx2mp-cli/bin/jsx2mp-build.js b/packages/jsx2mp-cli/bin/jsx2mp-build.js deleted file mode 100644 index 952e0102f..000000000 --- a/packages/jsx2mp-cli/bin/jsx2mp-build.js +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env node -const { resolve } = require('path'); -const program = require('commander'); -const { DEFAULT_TYPE, DEFAULT_PLATFORM, DEFAULT_ENTRY, DEFAULT_DIST, DEFAULT_CONSTANT_DIR } = require('../default'); - -program - .option('-t, --type ', 'set type of project | component', DEFAULT_TYPE) - .option('-p, --platform ', 'set target mini-application platform', DEFAULT_PLATFORM) - .option('-e, --entry ', 'set entry of component', DEFAULT_ENTRY) - .option('-d, --dist ', 'set export path', DEFAULT_DIST) - .option('-s, --skip-clear-stdout', 'skip clear stdout of screen', false) - .option('-c, --constant-dir ', 'set constant directory to copy', DEFAULT_CONSTANT_DIR) - .option('-n, --disable-copy-npm', 'disable copy node_modules action', false) - .option('-u, --turn-off-check-update', 'turn off package update check', false) - .action((cmd) => { - const workDirectory = resolve(process.env.CWD || process.cwd()); - const distDirectory = resolve(workDirectory, cmd.dist); - - const options = { - workDirectory, - distDirectory, - enableWatch: false, - type: cmd.type, - entry: cmd.entry, - dist: cmd.dist, - platform: cmd.platform, - skipClearStdout: cmd.skipClearStdout, - constantDir: cmd.constantDir === '' ? [] : cmd.constantDir.split(',').map(c => c.trim()), - disableCopyNpm: cmd.disableCopyNpm, - turnOffCheckUpdate: cmd.turnOffCheckUpdate - }; - - require('..').build(options); - }); - -program.parse(process.argv); diff --git a/packages/jsx2mp-cli/bin/jsx2mp-start.js b/packages/jsx2mp-cli/bin/jsx2mp-start.js deleted file mode 100644 index 18b4d18bc..000000000 --- a/packages/jsx2mp-cli/bin/jsx2mp-start.js +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env node -const { resolve } = require('path'); -const program = require('commander'); -const { DEFAULT_TYPE, DEFAULT_PLATFORM, DEFAULT_ENTRY, DEFAULT_DIST, DEFAULT_CONSTANT_DIR } = require('../default'); - -program - .option('-t, --type ', 'set type of project | component', DEFAULT_TYPE) - .option('-p, --platform ', 'set target mini-application platform', DEFAULT_PLATFORM) - .option('-e, --entry ', 'set entry of component', DEFAULT_ENTRY) - .option('-d, --dist ', 'set export path', DEFAULT_DIST) - .option('-s, --skip-clear-stdout', 'skip clear stdout of screen', false) - .option('-c, --constant-dir ', 'set constant directory to copy', DEFAULT_CONSTANT_DIR) - .option('-n, --disable-copy-npm', 'disable copy node_modules action', false) - .option('-m, --turn-off-source-map', 'turn off source map in dev mode', false) - .option('-u, --turn-off-check-update', 'turn off package update check', false) - .action((cmd) => { - const workDirectory = resolve(process.env.CWD || process.cwd()); - const distDirectory = resolve(workDirectory, cmd.dist); - - const options = { - workDirectory, - distDirectory, - enableWatch: true, - type: cmd.type, - entry: cmd.entry, - dist: cmd.dist, - platform: cmd.platform, - skipClearStdout: cmd.skipClearStdout, - constantDir: cmd.constantDir === '' ? [] : cmd.constantDir.split(',').map(c => c.trim()), - disableCopyNpm: cmd.disableCopyNpm, - turnOffSourceMap: cmd.turnOffSourceMap, - turnOffCheckUpdate: cmd.turnOffCheckUpdate - }; - require('..').watch(options); - }); - -program.parse(process.argv); diff --git a/packages/jsx2mp-cli/bin/jsx2mp.js b/packages/jsx2mp-cli/bin/jsx2mp.js deleted file mode 100755 index 70b9ec074..000000000 --- a/packages/jsx2mp-cli/bin/jsx2mp.js +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env node - -const program = require('commander'); -const packageInfo = require('../package.json'); - -program - .description('Run JSX in mini-program. website: https://github.com/alibaba/rax') - .version(packageInfo.version) - .usage(' [options]') - .command('start', 'Start a dev watch mode (hot-reload) to transform project.') - .command('build', 'Build project in production mode') - .on('command:*', (cmd) => { - if (!program.commands.find(c => c._name == cmd[0])) { - console.error(`Invalid command: ${program.args.join(' ')}\n`); - program.outputHelp(); - process.exit(1); - } - }) - .parse(process.argv); diff --git a/packages/jsx2mp-cli/checkPkgVersion.js b/packages/jsx2mp-cli/checkPkgVersion.js deleted file mode 100644 index 605e2c89a..000000000 --- a/packages/jsx2mp-cli/checkPkgVersion.js +++ /dev/null @@ -1,28 +0,0 @@ -const updateNotifier = require('update-notifier'); - -const jsx2mpCliPkg = require('./package.json'); -const jsx2mpLoaderPkg = require('jsx2mp-loader/package.json'); -// eslint-disable-next-line -const jsx2mpCompilerPkg = require('jsx-compiler/package.json'); -const jsx2mpRuntimePkg = require('jsx2mp-runtime/package.json'); - -const pkgVersion = [ - jsx2mpCliPkg, - jsx2mpLoaderPkg, - jsx2mpCompilerPkg, - jsx2mpRuntimePkg -]; - -let needUpdate = false; - -pkgVersion.forEach(pkg => { - const notifier = updateNotifier({ - pkg, - updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week - }); - if (notifier.update) { - needUpdate = true; - } -}); - -module.exports = needUpdate; diff --git a/packages/jsx2mp-cli/default.js b/packages/jsx2mp-cli/default.js deleted file mode 100644 index b43c5cf1a..000000000 --- a/packages/jsx2mp-cli/default.js +++ /dev/null @@ -1,7 +0,0 @@ -exports.DEFAULT_TYPE = 'project'; -exports.DEFAULT_PLATFORM = 'ali'; -exports.DEFAULT_ENTRY = 'src/app'; -exports.DEFAULT_DIST = 'dist'; -exports.DEFAULT_CONSTANT_DIR = ''; -exports.DEFAULT_CONSTANT_DIR_ARR = []; - diff --git a/packages/jsx2mp-cli/demo/assets/rax.png b/packages/jsx2mp-cli/demo/assets/rax.png deleted file mode 100644 index 393bdd1509a9de1d1a5db90c032060d2b5ef1c54..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 916 zcmV;F18e+=P)Px#PEbr#MMrQ<|Gfb6p$7c00RFN8;FAsWoCqHm0{^@L z?41huqXzGY5dO9R|GNO~h7s_L5C6ab>Vy>jvjP9C0RN=`|C#{xpbPn`2lAE2zEiq1{|00PKKL_t(o!>yN#lB*yPM56`} z)Cl;9{{N5O0epZF9lYB~wnEi%($fQ|uU8=c`V-OWZ$OoL1|q?T5v3l1xT^A?EcFcZ zG1KyJtkfqN)Y^F!Wm`NBL=w|ci&|=Dl2$ze1%*0tw|yaPAFQV$7aqe@t1* zstY;u?1P?hfH7NbiRBMCvvo61^8{K@ElBBj&?j>Cv(r_smQWLAun88T}S)%v?eqg}!)1ymrH zH5<);L#A88*3F8M4Q@47TJ8c`8M=YOFfF5lyc2@MhhE-uZad!&`W_?S?5?DtL||ln z-K8N`Q&u;@_%fa%ijg(rMJ7>gC&Mswu{zAkEcW5Wau$GzCd}dY8P9fiQOt0Kac3!6 zIaw5wUt(Mud~0ML<5ZUzS-`x#C_9XF`w}A?QIvk`E^0z8;-yFyTQpY<|5=a`%#enW z=NPjQ;NAbH8*aSx;nvJ(mYPit3}Z)!#zhwGKRe$EJ#hLy2q!m3d=uFm=a}Bw3BxgK zjD>r9DcAhKX}_%(_~;nr3m zNp>t@d3PFrjXbWuZiB$5e9EDg;2f8R*!VWH zwfE=1sR^=IJ4Cy0$1@LgOAK?(jc})}6)X9`kXYwChW&oL7ZfNv8)MUv)7)1^^_hOI qbho{)-)G9oQ1=lroKVj~NYFng#+RdS6`RTc0000 - Hello World! - - - ); -} diff --git a/packages/jsx2mp-cli/demo/package.json b/packages/jsx2mp-cli/demo/package.json deleted file mode 100644 index 10c52233d..000000000 --- a/packages/jsx2mp-cli/demo/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "private": true, - "name": "jsx2mp-cli-demo", - "version": "1.0.0", - "main": "component.js", - "dependencies": { - "rax": "^1.0.8", - "rax-image": "^1.1.1", - "rax-view": "^1.0.2" - } -} diff --git a/packages/jsx2mp-cli/getWebpackConfig.js b/packages/jsx2mp-cli/getWebpackConfig.js deleted file mode 100644 index c1573b626..000000000 --- a/packages/jsx2mp-cli/getWebpackConfig.js +++ /dev/null @@ -1,214 +0,0 @@ -const webpack = require('webpack'); -const { readJSONSync } = require('fs-extra'); -const { join, relative, dirname, sep } = require('path'); -const chalk = require('chalk'); -const RuntimeWebpackPlugin = require('./plugins/runtime'); -const spinner = require('./utils/spinner'); -const { multipleModuleResolve } = require('./utils/moduleResolve'); -const platformConfig = require('./utils/platformConfig'); - -const AppLoader = require.resolve('jsx2mp-loader/src/app-loader'); -const PageLoader = require.resolve('jsx2mp-loader/src/page-loader'); -const ComponentLoader = require.resolve('jsx2mp-loader/src/component-loader'); -const ScriptLoader = require.resolve('jsx2mp-loader/src/script-loader'); -const FileLoader = require.resolve('jsx2mp-loader/src/file-loader'); - - -const BabelLoader = require.resolve('babel-loader'); -let buildStartTime; - -function getPlatformExtensions(platform, extensions) { - return [ - ...platform ? extensions.map((ext) => `.${platform}${ext}`) : [], - ...extensions, - ]; -} - -function getBabelConfig() { - return { - presets: [ - require.resolve('@babel/preset-env'), - [require.resolve('@babel/preset-react'), { - 'throwIfNamespace': false - }] - ], - plugins: [ - [require.resolve('@babel/plugin-transform-typescript'), { - isTSX: true, - jsxPragma: 'Rax' - }], - require.resolve('@babel/plugin-proposal-export-default-from'), - require.resolve('@babel/plugin-proposal-class-properties'), - ], - }; -} - -function getEntry(type, cwd, entryFilePath, options) { - const entryPath = dirname(entryFilePath); - const entry = {}; - const { platform = 'ali', constantDir, mode, disableCopyNpm, turnOffSourceMap } = options; - - const loaderParams = { - platform: platformConfig[platform], - entryPath: entryFilePath, - constantDir, - mode, - disableCopyNpm, - turnOffSourceMap - }; - - if (type === 'project') { - let appConfig = null; - try { - appConfig = readJSONSync(join(cwd, entryPath, 'app.json')); - } catch (err) { - console.log(err); - console.error('Can not found app.json in current work directory, please check.'); - process.exit(1); - } - entry.app = AppLoader + '?' + JSON.stringify({ entryPath, platform: platformConfig[platform], mode, disableCopyNpm, turnOffSourceMap }) + '!./' + entryFilePath; - if (Array.isArray(appConfig.routes)) { - appConfig.routes.filter(({ targets }) => { - return !Array.isArray(targets) || targets.indexOf('miniapp') > -1; - }).forEach(({ source, component, window = {} }) => { - component = source || component; - entry['page@' + component] = PageLoader + '?' + JSON.stringify(Object.assign({ pageConfig: window }, loaderParams)) + '!' + getDepPath(component, entryPath); - }); - } else if (Array.isArray(appConfig.pages)) { - // Compatible with pages. - appConfig.pages.forEach((pagePath) => { - entry['page@' + pagePath] = PageLoader + '?' + JSON.stringify(loaderParams) + '!' + getDepPath(pagePath, entryPath); - }); - } - } - if (type === 'component') { - entry.component = ComponentLoader + '?' + JSON.stringify(loaderParams) + '!' + entryFilePath; - } - return entry; -} - -/** - * ./pages/foo -> based on src, return original - * /pages/foo -> based on rootContext - * pages/foo -> based on src, add prefix: './' - */ -function getDepPath(path, rootContext) { - if (path[0] === '.' || path[0] === sep) { - return join(rootContext, path); - } else { - return ['.', rootContext, path].join(sep); - } -} - -/** - * Add ./ (Linux/Unix) or .\ (Windows) at the start of filepath - * @param {string} filepath - * @returns {string} - */ -function addRelativePathPrefix(filepath) { - return filepath[0] !== '.' ? `.${sep}${filepath}` : filepath; -} - -module.exports = (options = {}) => { - let { entryPath, type, workDirectory, distDirectory, platform = 'ali', mode, constantDir, disableCopyNpm, turnOffSourceMap } = options; - entryPath = addRelativePathPrefix(entryPath); - entryPath = multipleModuleResolve(workDirectory, entryPath, ['.js', '.jsx', '.ts', '.tsx']) || entryPath; - const relativeEntryFilePath = addRelativePathPrefix(relative(workDirectory, entryPath)); // src/app.js or src/mobile/index.js - - const config = { - mode: 'production', // Will be fast - entry: getEntry(type, workDirectory, relativeEntryFilePath, options), - output: { - path: distDirectory - }, - target: 'node', - context: workDirectory, - module: { - rules: [ - { - test: /\.t|jsx?$/, - use: [ - { - loader: ScriptLoader, - options: { - mode: options.mode, - entryPath: relativeEntryFilePath, - platform: platformConfig[platform], - constantDir, - disableCopyNpm, - turnOffSourceMap - }, - }, - { - loader: BabelLoader, - options: getBabelConfig(), - } - ] - }, - { - test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.webp$/], - loader: FileLoader, - options: { - entryPath: relativeEntryFilePath - }, - }, - { - test: /\.json$/, - use: [{ - loader: ScriptLoader, - options: { - mode: options.mode, - entryPath: relativeEntryFilePath, - platform: platformConfig[platform], - constantDir, - disableCopyNpm, - turnOffSourceMap - }, - }] - } - ], - }, - resolve: { - extensions: getPlatformExtensions(platform, ['.js', '.jsx', '.ts', '.tsx', '.json']), - mainFields: ['main', 'module'] - }, - externals: [ - function(context, request, callback) { - if (/^@core\//.test(request)) { - return callback(null, `commonjs2 ${request}`); - } - if (/\.(css|sass|scss|styl|less)$/.test(request)) { - return callback(null, `commonjs2 ${request}`); - } - if (/^@weex-module\//.test(request)) { - return callback(null, `commonjs2 ${request}`); - } - callback(); - }, - ], - plugins: [ - new webpack.WatchIgnorePlugin([ - /node_modules/ - ]), - new webpack.DefinePlugin({ - 'process.env': { - NODE_ENV: mode === 'build' ? '"production"' : '"development"', - } - }), - new webpack.ProgressPlugin( (percentage, message) => { - if (percentage === 0) { - buildStartTime = Date.now(); - spinner.start(`[${platformConfig[platform].name}] Compiling...`); - } else if (percentage === 1) { - const endTime = Date.now(); - spinner.succeed(`${chalk.green('Successfully compiled!')}\n\nCost: [${endTime - buildStartTime}ms]`); - } - }) - ], - }; - - if (!disableCopyNpm) { - config.plugins.push(new RuntimeWebpackPlugin({ platform, mode })); - } - return config; -}; diff --git a/packages/jsx2mp-cli/index.js b/packages/jsx2mp-cli/index.js deleted file mode 100644 index d243119cb..000000000 --- a/packages/jsx2mp-cli/index.js +++ /dev/null @@ -1,189 +0,0 @@ -const { join } = require('path'); -const MemFs = require('memory-fs'); -const mergeWebpack = require('webpack-merge'); -const webpack = require('webpack'); -const consoleClear = require('console-clear'); -const chalk = require('chalk'); -const del = require('del'); -const chokidar = require('chokidar'); - -const getWebpackConfig = require('./getWebpackConfig'); -const spinner = require('./utils/spinner'); -const { getCurrentDirectoryPath } = require('./utils/file'); -const { DEFAULT_TYPE, DEFAULT_PLATFORM, DEFAULT_ENTRY, DEFAULT_DIST, DEFAULT_CONSTANT_DIR_ARR } = require('./default'); -const { copySync, existsSync, mkdirSync } = require('fs-extra'); - - -const cwd = process.cwd(); - -/** - * Start jsx2mp build. - * @param options - */ -function build(options = {}) { - const { - afterCompiled, - type = DEFAULT_TYPE, - entry = DEFAULT_ENTRY, - platform = DEFAULT_PLATFORM, - workDirectory = cwd, - distDirectory = join(cwd, DEFAULT_DIST), - skipClearStdout = false, - constantDir = DEFAULT_CONSTANT_DIR_ARR, - disableCopyNpm = false, - turnOffCheckUpdate = false - } = options; - - // Clean the dist dir before generating - if (existsSync(distDirectory)) { - del.sync(distDirectory + '/**'); - } - - constantDir.forEach(dir => copyConstantDir(dir, distDirectory)); - - const needUpdate = checkNeedUpdate(turnOffCheckUpdate); - - let config = getWebpackConfig({ - mode: 'build', - entryPath: entry, - platform, - type, - workDirectory, - distDirectory, - constantDir, - disableCopyNpm - }); - - if (options.webpackConfig) { - config = mergeWebpack(config, options.webpackConfig); - } - spinner.shouldClear = !skipClearStdout; - - const compiler = webpack(config); - compiler.outputFileSystem = new MemFs(); - compiler.run((err, stats) => { - handleCompiled(err, stats, { skipClearStdout }); - afterCompiled && afterCompiled(err, stats); - if (needUpdate) { - console.log(chalk.black.bgYellow.bold('Update for miniapp related packages available, please reinstall dependencies.')); - } - }); -} - -/** - * Start webpack watch mode. - * @param options - */ -function watch(options = {}) { - const { - afterCompiled, - type = DEFAULT_TYPE, - entry = DEFAULT_ENTRY, - platform = DEFAULT_PLATFORM, - workDirectory = cwd, - distDirectory = join(cwd, DEFAULT_DIST), - skipClearStdout = false, - constantDir = DEFAULT_CONSTANT_DIR_ARR, - disableCopyNpm = false, - turnOffSourceMap = false, - turnOffCheckUpdate = false - } = options; - - watchConstantDir(constantDir, distDirectory); - - const needUpdate = checkNeedUpdate(turnOffCheckUpdate); - - let config = getWebpackConfig({ - mode: 'watch', - entryPath: entry, - type, - workDirectory, - platform, - distDirectory, - constantDir, - disableCopyNpm, - turnOffSourceMap - }); - - if (options.webpackConfig) { - config = mergeWebpack(config, options.webpackConfig); - } - spinner.shouldClear = !skipClearStdout; - - const compiler = webpack(config); - - const watchOpts = { - aggregateTimeout: 600 - }; - compiler.outputFileSystem = new MemFs(); - compiler.watch(watchOpts, (err, stats) => { - handleCompiled(err, stats, { skipClearStdout }); - afterCompiled && afterCompiled(err, stats); - if (needUpdate) { - console.log(chalk.black.bgYellow.bold('Update for miniapp related packages available, please reinstall dependencies.')); - } - console.log('Watching for changes...'); - }); -} - -function handleCompiled(err, stats, { skipClearStdout }) { - if (err) { - console.error(err.stack || err); - if (err.details) { - console.error(err.details); - } - return; - } - if (stats.hasErrors()) { - const errors = stats.compilation.errors; - if (!skipClearStdout) consoleClear(true); - spinner.fail('Failed to compile.\n'); - for (let e of errors) { - console.log(chalk.red(` ${errors.indexOf(e) + 1}. ${e.error.message} \n`)); - if (process.env.DEBUG === 'true') { - console.log(e.error.stack); - } - } - console.log(chalk.yellow('Set environment `DEBUG=true` to see detail error stacks.')); - } -} - -/** - * watch and copy constant dir file change - * @param {array} dirs - * @param {string} distDirectory - */ -function watchConstantDir(dirs, distDirectory) { - const watcher = chokidar.watch(dirs); - watcher.on('all', (event, path) => { - copyConstantDir(path, distDirectory); - }); -} - -/** - * copy constant path to dist - * @param {string} path - * @param {string} distDirectory - */ -function copyConstantDir(path, distDirectory) { - if (!path) { - return; - } - if (!existsSync(path)) { - mkdirSync(path); - } - copySync(path, join(distDirectory, getCurrentDirectoryPath(path, 'src')), { - filter: (filename) => !/\.ts$/.test(filename), - }); -} - -function checkNeedUpdate(turnOff) { - if (turnOff) { - return false; - } - return require('./checkPkgVersion'); -} - -exports.build = build; -exports.watch = watch; -exports.getWebpackConfig = getWebpackConfig; diff --git a/packages/jsx2mp-cli/package.json b/packages/jsx2mp-cli/package.json deleted file mode 100644 index afbcf4755..000000000 --- a/packages/jsx2mp-cli/package.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "jsx2mp-cli", - "version": "0.3.1", - "license": "BSD-3-Clause", - "description": "A cli tool to transform Rax JSX based project to MiniApp.", - "bin": { - "jsx2mp": "bin/jsx2mp.js" - }, - "scripts": { - "test": "jest", - "test:watch": "npm run test -- --watchAll" - }, - "homepage": "https://github.com/alibaba/rax#readme", - "engine": { - "node": ">=8" - }, - "author": "Rax Team", - "dependencies": { - "@babel/plugin-proposal-class-properties": "^7.5.5", - "@babel/plugin-proposal-export-default-from": "^7.5.2", - "@babel/plugin-transform-typescript": "^7.7.4", - "@babel/preset-env": "^7.5.5", - "@babel/preset-react": "^7.0.0", - "babel-loader": "^8.0.6", - "chalk": "^2.4.2", - "chokidar": "^3.3.1", - "commander": "^2.20.0", - "console-clear": "^1.1.1", - "del": "^5.1.0", - "fs-extra": "^7.0.1", - "inquirer": "^6.2.2", - "jsx2mp-loader": "^0.3.0", - "jsx2mp-runtime": "^0.4.1", - "kebab-case": "^1.0.0", - "memory-fs": "^0.4.1", - "ora": "^3.4.0", - "terser": "^4.3.8", - "update-notifier": "^3.0.1", - "webpack": "^4.38.0", - "webpack-cli": "^3.3.6", - "webpack-merge": "^4.2.1" - }, - "devDependencies": { - "jest": "^24.5.0" - } -} diff --git a/packages/jsx2mp-cli/plugins/runtime.js b/packages/jsx2mp-cli/plugins/runtime.js deleted file mode 100644 index dd46fe0ab..000000000 --- a/packages/jsx2mp-cli/plugins/runtime.js +++ /dev/null @@ -1,40 +0,0 @@ -const { join } = require('path'); -const { copySync, writeFileSync, readJSONSync, readFileSync } = require('fs-extra'); -const { minify } = require('terser'); - -/** - * Runtime packages should be a dependency of jsx2mp-cli, - * for convenient to copy vendors. - */ -const runtime = 'jsx2mp-runtime'; -const runtimePackageJSONPath = require.resolve(join(runtime, 'package.json')); -const runtimePackageJSON = readJSONSync(runtimePackageJSONPath); -const runtimePackagePath = join(runtimePackageJSONPath, '..'); - -module.exports = class JSX2MPRuntimePlugin { - constructor({ platform = 'ali', mode = 'build' }) { - this.platform = platform; - this.mode = mode; - } - - apply(compiler) { - compiler.hooks.emit.tapAsync( - 'JSX2MPRuntimePlugin', - (compilation, callback) => { - const runtimeTargetPath = runtimePackageJSON.miniprogram && runtimePackageJSON.miniprogram[this.platform] - ? runtimePackageJSON.miniprogram[this.platform] - : runtimePackageJSON.main || 'index.js'; - const sourceFile = require.resolve(join(runtimePackagePath, runtimeTargetPath)); - const targetFile = join(compiler.outputPath, 'npm', runtime + '.js'); - - if (this.mode === 'build') { - const sourceCode = minify(readFileSync(sourceFile, 'utf-8')).code; - writeFileSync(targetFile, sourceCode); - } else { - copySync(sourceFile, targetFile); - } - callback(); - } - ); - } -}; diff --git a/packages/jsx2mp-cli/utils/file.js b/packages/jsx2mp-cli/utils/file.js deleted file mode 100644 index af200eda4..000000000 --- a/packages/jsx2mp-cli/utils/file.js +++ /dev/null @@ -1,59 +0,0 @@ -const { - readFileSync, - lstatSync, - ensureFileSync, - writeFileSync -} = require('fs-extra'); -const { relative } = require('path'); -const chalk = require('chalk'); - -/** - * Get file content as utf-8 text. - * @param path {String} Absolute path to a text file. - */ -const getFileContent = function(path) { - return readFileSync(path, 'utf-8'); -}; - -/** - * Judge a path is a directory. - * @param path {String} Absolute path to a file or directory. - * @return {Boolean} - */ -const isDirectory = function(path) { - return lstatSync(path).isDirectory(); -}; - -/** - * Write file and ensure folder exists. - * @param path {String} File path. - * @param content {String} File content. - * @param rootPath {String} project path. - * @private - */ -const writeFile = function(path, content, rootPath) { - ensureFileSync(path); - console.log(chalk.green('Write'), relative(rootPath, path)); - writeFileSync(path, content, 'utf-8'); -}; - -/** - * Get directory path under root - * @param {string} dirname e.g. src/constant/test - * @param {string} root e.g. src - * @returns {string} e.g. constant/test - */ -const getCurrentDirectoryPath = function(dirname, root = 'src') { - const rootPosition = dirname.indexOf(root); - if (rootPosition === -1) { - throw new Error(`Current directory ${dirname} is not under ${root}`); - } - return dirname.slice(rootPosition + root.length); -}; - -module.exports = { - isDirectory, - getFileContent, - writeFile, - getCurrentDirectoryPath -}; diff --git a/packages/jsx2mp-cli/utils/log.js b/packages/jsx2mp-cli/utils/log.js deleted file mode 100644 index bd9e89680..000000000 --- a/packages/jsx2mp-cli/utils/log.js +++ /dev/null @@ -1,26 +0,0 @@ -const inquirer = require('inquirer'); - -/** - * Standard method to print logs. - * @param logs - */ -const printLog = function(...logs) { - console.log.apply(console, logs); -}; - -/** - * Create an ask prase. - * @param message {String} - * @return {Promise} Answer true or false. - */ -const ask = function(message, defaultVal = true) { - const name = '_NAME_'; - return inquirer.prompt([ - { type: 'confirm', name, message, default: defaultVal } - ]).then(answers => answers[name]); -}; - -module.exports = { - printLog, - ask -}; \ No newline at end of file diff --git a/packages/jsx2mp-cli/utils/moduleResolve.js b/packages/jsx2mp-cli/utils/moduleResolve.js deleted file mode 100644 index a1e3735df..000000000 --- a/packages/jsx2mp-cli/utils/moduleResolve.js +++ /dev/null @@ -1,120 +0,0 @@ -const { sep, join, dirname } = require('path'); -const { existsSync, statSync, readFileSync } = require('fs-extra'); - -function startsWith(prevString, nextString) { - return prevString.indexOf(nextString) === 0; -} - -function startsWithArr(prevString, nextStringArr = []) { - return nextStringArr.some(nextString => startsWith(prevString, nextString)); -} - -function loadAsFile(module, extension) { - if (existsSync(module + extension) && statSync(module + extension).isFile()) { - return module + extension; - } - - if (existsSync(module) && statSync(module).isFile()) { - return module; - } -} - -function loadAsDirectory(module, extension) { - if (!existsSync(module)) { - return; - } - - let stat = statSync(module); - - if (stat.isDirectory()) { - const packagePath = join(module, 'package.json'); - const indexFile = join(module, 'index' + extension); - if (existsSync(packagePath) && statSync(packagePath).isFile()) { - let pkg = JSON.parse(readFileSync(packagePath, 'utf-8')); - let main = join(module, pkg.main || 'index' + extension); - return loadAsFile(main) || loadAsDirectory(main); - } else if (existsSync(indexFile) && statSync(indexFile).isFile()) { - return indexFile; - } - } else if (stat.isFile()) { - return loadAsFile(module, extension); - } -} - -function nodeModulesPaths(start) { - let parts = start.split(sep); - - if (!parts[parts.length - 1]) { - parts.pop(); - } - - let i = parts.length - 1; - let dirs = []; - while (i >= 0) { - if ('node_modules' === parts[i]) { - i -= 1; - continue; - } - let dir = join(parts.slice(0, i + 1).join(sep) || sep, 'node_modules'); - dirs.push(dir); - i -= 1; - } - return dirs; -} - -function loadNpmModules(module, start, extension) { - let target; - let paths = nodeModulesPaths(start); - - for (let i = 0; i < paths.length; ++i) { - let dependencyPath = join(paths[i], module); - target = loadAsFile(dependencyPath, extension) || loadAsDirectory(dependencyPath, extension); - - if (target) { - break; - } - } - return target; -} - -/** - * Resolve node path. - * @param {string} script - * @param {string} dependency - * @param {string} extension - * @return {*} - */ -function moduleResolve(script, dependency, extension = '.js') { - let target; - - if (startsWithArr(dependency, ['./', '../', '/', '.\\', '..\\', '\\'])) { - let dependencyPath = join(script, dependency); - target = loadAsFile(dependencyPath, extension) || loadAsDirectory(dependencyPath, extension); - } else { - target = loadNpmModules(dependency, dirname(script), extension); - } - return target; -}; - -/** - * - * - * @param {string} script - * @param {string} dependency - * @param {array} [extensions=[]] - * @returns - */ -function multipleModuleResolve(script, dependency, extensions = []) { - for (let extension of extensions) { - const target = moduleResolve(script, dependency, extension); - if (target) { - return target; - } - } - return null; -} - -module.exports = { - moduleResolve, - multipleModuleResolve -}; diff --git a/packages/jsx2mp-cli/utils/platformConfig.js b/packages/jsx2mp-cli/utils/platformConfig.js deleted file mode 100644 index f78ff05e1..000000000 --- a/packages/jsx2mp-cli/utils/platformConfig.js +++ /dev/null @@ -1,33 +0,0 @@ -module.exports = { - 'ali': { - type: 'ali', - name: 'Alibaba MiniApp', - extension: { - xml: '.axml', - css: '.acss', - } - }, - 'wechat': { - type: 'wechat', - name: 'WeChat MiniProgram', - extension: { - xml: '.wxml', - css: '.wxss', - } - }, - 'baidu': { - type: 'baidu', - name: 'Baidu SmartProgram', - extension: { - xml: '.swan', - css: '.css', - } - }, - 'tt': { - type: 'ByteDance MicroApp', - extension: { - xml: '.ttml', - css: '.ttss' - } - } -}; diff --git a/packages/jsx2mp-cli/utils/removeExt.js b/packages/jsx2mp-cli/utils/removeExt.js deleted file mode 100644 index a7fbd6eae..000000000 --- a/packages/jsx2mp-cli/utils/removeExt.js +++ /dev/null @@ -1,8 +0,0 @@ -const { extname } = require('path'); - -function removeExt(path) { - const ext = extname(path); - return path.slice(0, path.length - ext.length); -} - -module.exports = removeExt; diff --git a/packages/jsx2mp-cli/utils/spinner.js b/packages/jsx2mp-cli/utils/spinner.js deleted file mode 100644 index 87c1477e6..000000000 --- a/packages/jsx2mp-cli/utils/spinner.js +++ /dev/null @@ -1,18 +0,0 @@ -const ora = require('ora'); -const consoleClear = require('console-clear'); - -const methods = ['start', 'succeed']; -const spinner = ora({ spinner: 'arc' }); - -// Default to clear screen each time. -spinner.shouldClear = true; - -for (let method of methods) { - const tempMethod = spinner[method]; - spinner[method] = function(...arg) { - if (spinner.shouldClear) consoleClear(true); - tempMethod.apply(this, arg); - }; -} - -module.exports = spinner; diff --git a/packages/jsx2mp-loader/package.json b/packages/jsx2mp-loader/package.json deleted file mode 100644 index 3c88410f4..000000000 --- a/packages/jsx2mp-loader/package.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "jsx2mp-loader", - "version": "0.4.13", - "description": "", - "files": [ - "src" - ], - "main": "src/app-loader.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "Rax Team", - "license": "MIT", - "dependencies": { - "@babel/core": "^7.5.5", - "@babel/plugin-proposal-class-properties": "^7.5.5", - "@babel/plugin-proposal-export-default-from": "^7.5.2", - "@babel/plugin-transform-typescript": "^7.7.4", - "@babel/preset-env": "^7.5.5", - "babel-plugin-danger-remove-unused-import": "^2.0.0", - "babel-plugin-minify-dead-code-elimination": "^0.5.1", - "babel-plugin-transform-define": "^1.3.1", - "chalk": "^2.4.2", - "convert-source-map": "^1.6.0", - "csso": "^3.5.1", - "enhanced-resolve": "^4.1.1", - "fs-extra": "^8.1.0", - "jsx-compiler": "^0.4.0", - "less": "^3.10.3", - "loader-utils": "^1.2.3", - "pretty-data": "^0.40.0", - "sass": "^1.23.2", - "stylesheet-loader": "^0.8.0", - "stylus": "^0.54.7", - "terser": "^4.3.8" - } -} diff --git a/packages/jsx2mp-loader/src/app-loader.js b/packages/jsx2mp-loader/src/app-loader.js deleted file mode 100644 index 782c2046d..000000000 --- a/packages/jsx2mp-loader/src/app-loader.js +++ /dev/null @@ -1,96 +0,0 @@ -const { existsSync, mkdirpSync } = require('fs-extra'); -const { join } = require('path'); -const { getOptions } = require('loader-utils'); -const chalk = require('chalk'); -const { doubleBackslash, getHighestPriorityPackage } = require('./utils/pathHelper'); -const eliminateDeadCode = require('./utils/dce'); -const defaultStyle = require('./defaultStyle'); -const { QUICKAPP } = require('./constants'); -const processCSS = require('./styleProcessor'); -const output = require('./output'); -const { isTypescriptFile } = require('./utils/judgeModule'); -const parse = require('./utils/parseRequest'); - -function createImportStatement(req) { - return `import '${doubleBackslash(req)}';`; -} - -function generateDependencies(dependencies) { - return Object - .keys(dependencies) - .map(mod => createImportStatement(mod)) - .join('\n'); -} - -module.exports = async function appLoader(content) { - const query = parse(this.request); - // Only handle app role file - if (query.role !== 'app') { - return content; - } - - const loaderOptions = getOptions(this); - const { entryPath, outputPath, platform, mode, disableCopyNpm, turnOffSourceMap, aliasEntries } = loaderOptions; - const rawContent = content; - - if (!existsSync(outputPath)) mkdirpSync(outputPath); - - const sourcePath = join(this.rootContext, entryPath); - - const JSXCompilerPath = getHighestPriorityPackage('jsx-compiler', this.rootContext); - const compiler = require(JSXCompilerPath); - - const compilerOptions = Object.assign({}, compiler.baseOptions, { - resourcePath: this.resourcePath, - outputPath, - sourcePath, - platform, - type: 'app', - sourceFileName: this.resourcePath, - disableCopyNpm, - turnOffSourceMap, - aliasEntries - }); - - const rawContentAfterDCE = eliminateDeadCode(rawContent); - - let transformed; - try { - transformed = compiler(rawContentAfterDCE, compilerOptions); - } catch (e) { - console.log(chalk.red(`\n[${platform.name}] Error occured when handling App ${this.resourcePath}`)); - if (process.env.DEBUG === 'true') { - throw new Error(e); - } else { - const errMsg = e.node ? `${e.message}\nat ${this.resourcePath}` : `Unknown compile error! please check your code at ${this.resourcePath}`; - throw new Error(errMsg); - } - } - - const { style, assets } = await processCSS(transformed.cssFiles, sourcePath); - transformed.style = style; - transformed.assets = assets; - - const outputContent = { - code: transformed.code, - map: transformed.map, - css: transformed.style ? defaultStyle + transformed.style : defaultStyle, - }; - const outputOption = { - outputPath: { - code: join(outputPath, platform.type === QUICKAPP ? 'app.ux' : 'app.js'), - css: join(outputPath, 'app' + platform.extension.css), - }, - mode, - isTypescriptFile: isTypescriptFile(this.resourcePath), - type: 'app', - platform, - }; - - output(outputContent, rawContent, outputOption); - - return [ - `/* Generated by JSX2MP AppLoader, sourceFile: ${this.resourcePath}. */`, - generateDependencies(transformed.imported), - ].join('\n'); -}; diff --git a/packages/jsx2mp-loader/src/babel-plugin-rename-import.js b/packages/jsx2mp-loader/src/babel-plugin-rename-import.js deleted file mode 100644 index 4f64f0858..000000000 --- a/packages/jsx2mp-loader/src/babel-plugin-rename-import.js +++ /dev/null @@ -1,181 +0,0 @@ -const { join, relative, dirname, extname } = require('path'); -const enhancedResolve = require('enhanced-resolve'); -const chalk = require('chalk'); - -const { QUICKAPP } = require('./constants'); -const { isNpmModule, isWeexModule, isQuickAppModule, isRaxModule, isJsx2mpRuntimeModule, isNodeNativeModule } = require('./utils/judgeModule'); -const { addRelativePathPrefix, normalizeOutputFilePath, removeExt } = require('./utils/pathHelper'); -const getAliasCorrespondingValue = require('./utils/getAliasCorrespondingValue'); - -const RUNTIME = 'jsx2mp-runtime'; - -const getRuntimeByPlatform = (platform) => `${RUNTIME}/dist/jsx2mp-runtime.${platform}.esm`; - -const getRuntimeRelativePath = (distSourcePath, outputPath) => addRelativePathPrefix(normalizeOutputFilePath(join(relative(dirname(distSourcePath), join(outputPath, 'npm')), RUNTIME))); - -const defaultOptions = { - normalizeNpmFileName: (s) => s, -}; - -const transformPathMap = {}; - -const resolveWithTS = enhancedResolve.create.sync({ - extensions: ['.ts', '.js'] -}); - -module.exports = function visitor({ types: t }, options) { - options = Object.assign({}, defaultOptions, options); - const { normalizeNpmFileName, distSourcePath, resourcePath, outputPath, disableCopyNpm, platform, aliasEntries } = options; - const source = (value, rootContext) => { - // Example: - // value => '@ali/universal-goldlog' or '@ali/xxx/foo/lib' - // filename => '/Users/xxx/workspace/yyy/src/utils/logger.js' - // rootContext => '/Users/xxx/workspace/yyy/' - - const target = enhancedResolve.sync(resourcePath, value); - - const rootNodeModulePath = join(rootContext, 'node_modules'); - const filePath = relative(dirname(distSourcePath), join(outputPath, 'npm', relative(rootNodeModulePath, target))); - let modifiedValue = normalizeNpmFileName(addRelativePathPrefix(normalizeOutputFilePath(filePath))); - // json file will be transformed to js file - if (extname(value) === '.json') { - modifiedValue = removeExt(modifiedValue); - } - return t.stringLiteral(modifiedValue); - }; - - // In WeChat MiniProgram, `require` can't get index file if index is omitted - const ensureIndexInPath = (value, resourcePath) => { - const target = resolveWithTS(dirname(resourcePath), value); - const result = relative(dirname(resourcePath), target); - return removeExt(addRelativePathPrefix(normalizeOutputFilePath(result))); - }; - - return { - visitor: { - ImportDeclaration(path, state) { - let { value } = path.node.source; - // Handle alias - const aliasCorrespondingValue = getAliasCorrespondingValue(aliasEntries, value, resourcePath); - if (aliasCorrespondingValue) { - path.node.source = t.stringLiteral(aliasCorrespondingValue); - value = path.node.source.value; - } - - if (isNpmModule(value)) { - if (isWeexModule(value)) { - path.remove(); - return; - } - if (isQuickAppModule(value)) { - if (platform.type === QUICKAPP) { - path.skip(); - } else { - path.remove(); - } - return; - } - if (isNodeNativeModule(value)) { - path.skip(); - return; - } - - if (isRaxModule(value)) { - const runtimePath = disableCopyNpm ? getRuntimeByPlatform(platform.type) : getRuntimeRelativePath(distSourcePath, outputPath); - path.node.source = t.stringLiteral(runtimePath); - transformPathMap[runtimePath] = true; - return; - } - - if (isJsx2mpRuntimeModule(value)) { - const runtimePath = disableCopyNpm ? value : getRuntimeRelativePath(distSourcePath, outputPath); - path.node.source = t.stringLiteral(runtimePath); - transformPathMap[runtimePath] = true; - return; - } - - if (!disableCopyNpm) { - const processedSource = source(value, state.cwd); - // Add lock to avoid repeatly transformed in CallExpression if @babel/preset-env invoked - transformPathMap[processedSource.value] = true; - path.node.source = processedSource; - } - } else { - const ensuredPath = ensureIndexInPath(value, resourcePath); - path.node.source = t.stringLiteral(ensuredPath); - } - }, - - CallExpression(path, state) { - const { node } = path; - if ( - node.callee.name === 'require' && - node.arguments && - node.arguments.length === 1 - ) { - if (t.isStringLiteral(node.arguments[0])) { - let moduleName = node.arguments[0].value; - // Handle alias - const aliasCorrespondingValue = getAliasCorrespondingValue(aliasEntries, moduleName, resourcePath); - if (aliasCorrespondingValue) { - path.node.arguments = [ - t.stringLiteral(aliasCorrespondingValue) - ]; - moduleName = node.arguments[0].value; - } - if (isNpmModule(moduleName)) { - if (isWeexModule(moduleName)) { - path.replaceWith(t.nullLiteral()); - return; - } - if (isQuickAppModule(moduleName)) { - if (platform.type === QUICKAPP) { - path.skip(); - } else { - path.replaceWith(t.nullLiteral()); - } - return; - } - if (isNodeNativeModule(moduleName)) { - path.skip(); - return; - } - - if (isRaxModule(moduleName)) { - const runtimePath = disableCopyNpm ? getRuntimeByPlatform(platform.type) : getRuntimeRelativePath(distSourcePath, outputPath); - path.node.arguments = [ - t.stringLiteral(runtimePath) - ]; - return; - } - - if (isJsx2mpRuntimeModule(moduleName)) { - const runtimePath = disableCopyNpm ? moduleName : getRuntimeRelativePath(distSourcePath, outputPath); - path.node.arguments = [ - t.stringLiteral(runtimePath) - ]; - return; - } - - if (!disableCopyNpm) { - const processedSource = source(moduleName, state.cwd); - transformPathMap[processedSource.value] = true; - path.node.arguments = [ processedSource ]; - } - } else { - if (!transformPathMap[moduleName]) { - path.node.arguments = [ - t.stringLiteral(ensureIndexInPath(moduleName, resourcePath)) - ]; - } - } - } else if (t.isExpression(node.arguments[0])) { - // require with expression, can not staticly find target. - console.warn(chalk.yellow(`Critical requirement of "${path.toString()}", which have been removed at \n${state.filename}.`)); - path.replaceWith(t.nullLiteral()); - } - } - } - } - }; -}; diff --git a/packages/jsx2mp-loader/src/cached.js b/packages/jsx2mp-loader/src/cached.js deleted file mode 100644 index 546425a59..000000000 --- a/packages/jsx2mp-loader/src/cached.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = function cached(fn) { - const cache = Object.create(null); - return function cachedFn(str) { - const hit = cache[str]; - return hit || (cache[str] = fn(str)); - }; -}; diff --git a/packages/jsx2mp-loader/src/component-loader.js b/packages/jsx2mp-loader/src/component-loader.js deleted file mode 100644 index 87488060d..000000000 --- a/packages/jsx2mp-loader/src/component-loader.js +++ /dev/null @@ -1,193 +0,0 @@ -const { existsSync, mkdirpSync } = require('fs-extra'); -const { relative, join, dirname, resolve } = require('path'); -const { getOptions } = require('loader-utils'); -const chalk = require('chalk'); -const cached = require('./cached'); -const { removeExt, isFromTargetDirs, doubleBackslash, normalizeOutputFilePath, addRelativePathPrefix, getHighestPriorityPackage } = require('./utils/pathHelper'); -const eliminateDeadCode = require('./utils/dce'); -const { isTypescriptFile } = require('./utils/judgeModule'); -const parse = require('./utils/parseRequest'); - -const processCSS = require('./styleProcessor'); -const output = require('./output'); - -const ScriptLoader = require.resolve('./script-loader'); -const MINIAPP_PLUGIN_COMPONENTS_REG = /^plugin\:\/\//; - -module.exports = async function componentLoader(content) { - const query = parse(this.request); - // Only handle component role file - if (query.role !== 'component') { - return content; - } - - const loaderOptions = getOptions(this); - const { platform, entryPath, outputPath, constantDir, mode, disableCopyNpm, turnOffSourceMap, aliasEntries, injectAppCssComponent } = loaderOptions; - const resourcePath = this.resourcePath; - const rootContext = this.rootContext; - const absoluteConstantDir = constantDir.map(dir => join(rootContext, dir)); - - const sourcePath = join(rootContext, dirname(entryPath)); - - const relativeSourcePath = relative(sourcePath, this.resourcePath); - const distFileWithoutExt = removeExt(join(outputPath, relativeSourcePath), platform.type); - - const isFromConstantDir = cached(isFromTargetDirs(absoluteConstantDir)); - - const JSXCompilerPath = getHighestPriorityPackage('jsx-compiler', this.rootContext); - const compiler = require(JSXCompilerPath); - - const compilerOptions = Object.assign({}, compiler.baseOptions, { - resourcePath: this.resourcePath, - outputPath, - sourcePath, - type: 'component', - platform, - sourceFileName: this.resourcePath, - disableCopyNpm, - turnOffSourceMap, - aliasEntries - }); - - const rawContentAfterDCE = eliminateDeadCode(content); - - let transformed; - try { - transformed = compiler(rawContentAfterDCE, compilerOptions); - } catch (e) { - console.log(chalk.red(`\n[${platform.name}] Error occured when handling Component ${this.resourcePath}`)); - if (process.env.DEBUG === 'true') { - throw new Error(e); - } else { - const errMsg = e.node ? `${e.message}\nat ${this.resourcePath}` : `Unknown compile error! please check your code at ${this.resourcePath}`; - throw new Error(errMsg); - } - } - - const { style, assets } = await processCSS(transformed.cssFiles, sourcePath); - transformed.style = style; - transformed.assets = assets; - - const config = Object.assign({}, transformed.config); - if (Array.isArray(transformed.dependencies)) { - transformed.dependencies.forEach(dep => { - this.addDependency(dep); - }); - } - if (config.usingComponents) { - const usingComponents = {}; - Object.keys(config.usingComponents).forEach(key => { - const value = config.usingComponents[key]; - - if (/^c-/.test(key)) { - const result = MINIAPP_PLUGIN_COMPONENTS_REG.test(value) ? value : removeExt(addRelativePathPrefix(relative(dirname(this.resourcePath), value))); - usingComponents[key] = normalizeOutputFilePath(result); - } else { - usingComponents[key] = normalizeOutputFilePath(value); - } - }); - config.usingComponents = usingComponents; - } - - const distFileDir = dirname(distFileWithoutExt); - if (!existsSync(distFileDir)) mkdirpSync(distFileDir); - - // Only works when developing miniapp plugin, to declare the use of __app_css component - if (injectAppCssComponent) { - const appCssComponentPath = resolve(outputPath, '__app_css', 'index'); - const relativeAppCssComponentPath = relative(distFileDir, appCssComponentPath); - config.usingComponents = { - '__app_css': relativeAppCssComponentPath, - ...config.usingComponents - }; - } - - const outputContent = { - code: transformed.code, - map: transformed.map, - css: transformed.style || '', - json: config, - template: transformed.template, - assets: transformed.assets, - importComponents: transformed.importComponents, - iconfontMap: transformed.iconfontMap, - }; - const outputOption = { - outputPath: { - code: distFileWithoutExt + '.js', - json: distFileWithoutExt + '.json', - css: distFileWithoutExt + platform.extension.css, - template: distFileWithoutExt + platform.extension.xml, - assets: outputPath - }, - mode, - platform, - isTypescriptFile: isTypescriptFile(this.resourcePath) - }; - - output(outputContent, content, outputOption); - - function isCustomComponent(name, usingComponents = {}) { - const matchingPath = join(dirname(resourcePath), name); - for (let key in usingComponents) { - if ( - usingComponents.hasOwnProperty(key) - && usingComponents[key] - && usingComponents[key].indexOf(matchingPath) === 0 - ) { - return true; - } - } - return false; - } - - const dependencies = []; - Object.keys(transformed.imported).forEach(name => { - if (isCustomComponent(name, transformed.usingComponents)) { - const componentPath = resolve(dirname(resourcePath), name); - dependencies.push({ - name: isFromConstantDir(componentPath) ? name : `${name}?role=component`, // Native miniapp component js file will loaded by script-loader - options: loaderOptions - }); - } else { - const importedArray = transformed.imported[name]; - let entirePush = false; - importedArray.forEach(importedContent => { - // Component library - if (importedContent.isFromComponentLibrary) { - dependencies.push({ - name, - loader: ScriptLoader, - options: Object.assign({}, loaderOptions, { - importedComponent: importedContent.local - }) - }); - } else { - if (!entirePush) { - dependencies.push({ name }); - entirePush = true; - } - } - }); - } - }); - - return [ - `/* Generated by JSX2MP ComponentLoader, sourceFile: ${this.resourcePath}. */`, - generateDependencies(dependencies), - ].join('\n'); -}; - -function generateDependencies(dependencies) { - return dependencies - .map(({ name, loader, options }) => { - let mod = name; - if (loader) mod = loader + '?' + JSON.stringify(options) + '!' + mod; - return createImportStatement(mod); - }) - .join('\n'); -} - -function createImportStatement(req) { - return `import '${doubleBackslash(req)}';`; -} diff --git a/packages/jsx2mp-loader/src/constants.js b/packages/jsx2mp-loader/src/constants.js deleted file mode 100644 index e2374bee5..000000000 --- a/packages/jsx2mp-loader/src/constants.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - MINIAPP: 'miniapp', - WECHAT_MINIPROGRAM: 'wechat-miniprogram', - QUICKAPP: 'quickapp', -}; diff --git a/packages/jsx2mp-loader/src/defaultStyle.js b/packages/jsx2mp-loader/src/defaultStyle.js deleted file mode 100644 index 948cb6394..000000000 --- a/packages/jsx2mp-loader/src/defaultStyle.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = `.__rax-view { - border: 0 solid black; - display:flex; - flex-direction:column; - align-content:flex-start; - flex-shrink:0; - box-sizing:border-box; -} -.__rax-text { - box-sizing: border-box; - display: block; - font-size: 32rpx; -} -`; diff --git a/packages/jsx2mp-loader/src/file-loader.js b/packages/jsx2mp-loader/src/file-loader.js deleted file mode 100644 index 890006abc..000000000 --- a/packages/jsx2mp-loader/src/file-loader.js +++ /dev/null @@ -1,19 +0,0 @@ -const { join, relative, dirname } = require('path'); -const { copySync } = require('fs-extra'); - -const loaderUtils = require('loader-utils'); - -module.exports = function fileLoader(content) { - const { entryPath, outputPath } = loaderUtils.getOptions(this) || {}; - const rootContext = this.rootContext; - - const relativeFilePath = relative( - join(rootContext, dirname(entryPath)), - this.resourcePath - ); - const distSourcePath = join(outputPath, relativeFilePath); - copySync(this.resourcePath, distSourcePath); - - return ''; -}; - diff --git a/packages/jsx2mp-loader/src/output.js b/packages/jsx2mp-loader/src/output.js deleted file mode 100644 index 25769ef31..000000000 --- a/packages/jsx2mp-loader/src/output.js +++ /dev/null @@ -1,244 +0,0 @@ -const { writeJSONSync, writeFileSync, readFileSync, existsSync, mkdirpSync } = require('fs-extra'); -const { extname, dirname, join, relative } = require('path'); -const { transformSync } = require('@babel/core'); -const { minify, minifyJS, minifyCSS, minifyXML } = require('./utils/minifyCode'); -const addSourceMap = require('./utils/addSourceMap'); -const { QUICKAPP } = require('./constants'); - -function transformCode(rawContent, mode, externalPlugins = [], externalPreset = []) { - const presets = [].concat(externalPreset); - const plugins = externalPlugins.concat([ - require('@babel/plugin-proposal-export-default-from'), // for support of export default - [ - require('babel-plugin-transform-define'), - { - 'process.env.NODE_ENV': mode === 'build' ? 'production' : 'development', - } - ], - [ - require('babel-plugin-minify-dead-code-elimination'), - { - optimizeRawSize: true, - keepFnName: true - } - ], - ]); - - - const babelParserOption = { - plugins: [ - 'classProperties', - 'jsx', - 'typescript', - 'trailingFunctionCommas', - 'asyncFunctions', - 'exponentiationOperator', - 'asyncGenerators', - 'objectRestSpread', - ['decorators', { decoratorsBeforeExport: false }], - 'dynamicImport', - ], // support all plugins - }; - - return transformSync(rawContent, { - presets, - plugins, - parserOpts: babelParserOption - }); -} - -/** - * Process and write file - * @param {object} content Compiled result - * @param {string} raw Original file content - * @param {object} options - */ -function output(content, raw, options) { - const { mode, outputPath, externalPlugins = [], isTypescriptFile, platform, type } = options; - let { code, config, json, css, map, template, assets, importComponents = [], iconfontMap } = content; - const isQuickApp = platform.type === QUICKAPP; - - if (isTypescriptFile) { - externalPlugins.unshift(require('@babel/plugin-transform-typescript')); - } - - if (mode === 'build') { - // Compile ES6 => ES5 and minify code - code && ( - code = minifyJS(transformCode(code, - mode, - externalPlugins.concat([require('@babel/plugin-proposal-class-properties')]), - [[require('@babel/preset-env'), { - exclude: ['@babel/plugin-transform-regenerator'] - }]] - ).code) - ); - config && ( - config = minifyJS(transformCode(config, - mode, - externalPlugins.concat([require('@babel/plugin-proposal-class-properties')]), - [require('@babel/preset-env')] - ).code) - ); - css && (css = minifyCSS(css)); - template && (template = minifyXML(template)); - } else { - if (code) { - code = transformCode(code, mode, externalPlugins).code; - // Add source map - if (map) { - code = addSourceMap(code, raw, map); - } - } - } - - // Write file - if (code) { - if (isQuickApp) { - // wrap with script for app.ux - if (type === 'app') { - code = `\n`; - writeFileWithDirCheck(outputPath.code, code); - // check if update fns exists - if (global._appUpdateFns && global._appUpdateFns.length) { - global._appUpdateFns.map(fn => { - fn.call(); - }); - global._appUpdateFns = []; - } - } else { - // insert global iconfont in app.ux if iconfont detected in page/component - if (iconfontMap && iconfontMap.length) { - const appPath = join(outputPath.assets, 'app.ux'); - let appContent = readFileSync(appPath, 'utf8'); - if (appContent.length) { - updateAppUx(appContent, iconfontMap, appPath); - } else { - // cache update fns in case app.ux is not ready yet - global._appUpdateFns = global._appUpdateFns || []; - global._appUpdateFns.push(updateAppUx.bind(null, appContent, iconfontMap, appPath)); - } - } - } - } - writeFileWithDirCheck(outputPath.code, code); - } - - if (json) { - writeFileWithDirCheck(outputPath.json, json, 'json'); - } - if (template) { - if (isQuickApp) { - if (importComponents && importComponents.length) { - template = `${importComponents.join('\n')}\n${template}\n`; - } - if (code) { - template += `\n`; - } - if (css && outputPath.css) { - template += `\n`; - } else { - template += `\n`; - } - } - writeFileWithDirCheck(outputPath.template, template); - } - if (css) { - if (isQuickApp) { - // add common style in css files - if (!css.includes('.__rax-view')) { - css = ` - .__rax-view { - border: 0 solid black; - display:flex; - flex-direction:column; - align-content:flex-start; - flex-shrink:0; - } - ${css}`; - } - css = css.replace(/rpx/g, 'px'); - } - writeFileWithDirCheck(outputPath.css, css); - } - if (config) { - writeFileWithDirCheck(outputPath.config, config); - } - - // Write extra assets - if (assets) { - Object.keys(assets).forEach((asset) => { - const ext = extname(asset); - let content = assets[asset]; - if (isQuickApp) { - content = content.replace(/rpx/g, 'px'); - } - if (mode === 'build') { - content = minify(content, ext); - } - const assetsOutputPath = join(outputPath.assets, asset); - writeFileWithDirCheck(assetsOutputPath, content); - }); - } -} - -/** - * Insert iconfont configure in app.ux - * @param {string} appContent Content of compiled app.ux - * @param {object} iconfontMap Compiled iconfont's map - * @param {string} appPath Path for app.ux - */ -function updateAppUx(appContent, iconfontMap, appPath) { - const insertIndex = appContent.indexOf(''); - if (insertIndex < 0) { - appContent = `${appContent}\n`; - } else { - appContent = `${appContent.substr(0, insertIndex)}\n${iconfontMap.map((v) => { - return `@font-face { - font-family: ${v.fontFamily}; - src: url('${v.url}'); -} -.${v.iconClass} { - font-family: ${v.fontFamily}; -}`; - }).join('\n')}\n`; - } - writeFileSync(appPath, appContent); -} - - -/** - * mkdir before write file if dir does not exist - * @param {string} filePath - * @param {string|Buffer|TypedArray|DataView} content - * @param {string} [type=file] 'file' or 'json' - */ -function writeFileWithDirCheck(filePath, content, type = 'file') { - const dirPath = dirname(filePath); - if (!existsSync(dirPath)) { - mkdirpSync(dirPath); - } - if (type === 'file') { - writeFileSync(filePath, content); - } else if (type === 'json') { - writeJSONSync(filePath, content, { spaces: 2 }); - } -} - -module.exports = output; diff --git a/packages/jsx2mp-loader/src/page-loader.js b/packages/jsx2mp-loader/src/page-loader.js deleted file mode 100644 index 6ab91e8d9..000000000 --- a/packages/jsx2mp-loader/src/page-loader.js +++ /dev/null @@ -1,197 +0,0 @@ -const { readFileSync, existsSync, mkdirpSync, readJSONSync } = require('fs-extra'); -const { relative, join, dirname, resolve } = require('path'); -const { getOptions } = require('loader-utils'); -const chalk = require('chalk'); -const cached = require('./cached'); -const { removeExt, isFromTargetDirs, doubleBackslash, normalizeOutputFilePath, addRelativePathPrefix, getHighestPriorityPackage } = require('./utils/pathHelper'); -const eliminateDeadCode = require('./utils/dce'); -const processCSS = require('./styleProcessor'); -const output = require('./output'); -const { isTypescriptFile } = require('./utils/judgeModule'); -const parse = require('./utils/parseRequest'); - -const ScriptLoader = require.resolve('./script-loader'); -const MINIAPP_PLUGIN_COMPONENTS_REG = /^plugin\:\/\//; - -module.exports = async function pageLoader(content) { - const query = parse(this.request); - // Only handle page role file - if (query.role !== 'page') { - return content; - } - - const loaderOptions = getOptions(this); - const { platform, entryPath, mode, disableCopyNpm, constantDir, turnOffSourceMap, outputPath, aliasEntries, injectAppCssComponent } = loaderOptions; - const resourcePath = this.resourcePath; - const rootContext = this.rootContext; - const absoluteConstantDir = constantDir.map(dir => join(rootContext, dir)); - - const sourcePath = join(rootContext, dirname(entryPath)); - const relativeSourcePath = relative(sourcePath, this.resourcePath); - const targetFilePath = join(outputPath, relativeSourcePath); - - const isFromConstantDir = cached(isFromTargetDirs(absoluteConstantDir)); - - const JSXCompilerPath = getHighestPriorityPackage('jsx-compiler', this.rootContext); - const compiler = require(JSXCompilerPath); - - const compilerOptions = Object.assign({}, compiler.baseOptions, { - resourcePath: this.resourcePath, - outputPath, - sourcePath, - type: 'page', - platform, - sourceFileName: this.resourcePath, - disableCopyNpm, - turnOffSourceMap, - aliasEntries - }); - - const rawContentAfterDCE = eliminateDeadCode(content); - - let transformed; - try { - transformed = compiler(rawContentAfterDCE, compilerOptions); - } catch (e) { - console.log(chalk.red(`\n[${platform.name}] Error occured when handling Page ${this.resourcePath}`)); - if (process.env.DEBUG === 'true') { - throw new Error(e); - } else { - const errMsg = e.node ? `${e.message}\nat ${this.resourcePath}` : `Unknown compile error! please check your code at ${this.resourcePath}`; - throw new Error(errMsg); - } - } - - const { style, assets } = await processCSS(transformed.cssFiles, sourcePath); - transformed.style = style; - transformed.assets = assets; - - const pageDistDir = dirname(targetFilePath); - if (!existsSync(pageDistDir)) mkdirpSync(pageDistDir); - - const distFileWithoutExt = removeExt(join(outputPath, relativeSourcePath), platform.type); - const pageConfigPath = distFileWithoutExt + '.json'; - let config = { - ...transformed.config - }; - if (existsSync(pageConfigPath)) { - const pageConfig = readJSONSync(pageConfigPath); - delete pageConfig.usingComponents; - Object.assign(config, pageConfig); - } - if (Array.isArray(transformed.dependencies)) { - transformed.dependencies.forEach(dep => { - this.addDependency(dep); - }); - } - - if (config.usingComponents) { - const usingComponents = {}; - Object.keys(config.usingComponents).forEach(key => { - const value = config.usingComponents[key]; - if (/^c-/.test(key)) { - const result = MINIAPP_PLUGIN_COMPONENTS_REG.test(value) ? value : removeExt(addRelativePathPrefix(relative(dirname(this.resourcePath), value))); - usingComponents[key] = normalizeOutputFilePath(result); - } else { - usingComponents[key] = normalizeOutputFilePath(value); - } - }); - config.usingComponents = usingComponents; - } - - // Only works when developing miniapp plugin, to declare the use of __app_css component - if (injectAppCssComponent) { - const appCssComponentPath = resolve(outputPath, '__app_css', 'index'); - const relativeAppCssComponentPath = relative(pageDistDir, appCssComponentPath); - config.usingComponents = { - '__app_css': relativeAppCssComponentPath, - ...config.usingComponents - }; - } - - const outputContent = { - code: transformed.code, - map: transformed.map, - css: transformed.style || '', - json: config, - template: transformed.template, - assets: transformed.assets, - importComponents: transformed.importComponents, - iconfontMap: transformed.iconfontMap, - }; - const outputOption = { - outputPath: { - code: distFileWithoutExt + '.js', - json: pageConfigPath, - css: distFileWithoutExt + platform.extension.css, - template: distFileWithoutExt + platform.extension.xml, - assets: outputPath - }, - mode, - platform, - isTypescriptFile: isTypescriptFile(this.resourcePath) - }; - - output(outputContent, content, outputOption); - - function isCustomComponent(name, usingComponents = {}) { - const matchingPath = join(dirname(resourcePath), name); - for (let key in usingComponents) { - if (usingComponents.hasOwnProperty(key) - && usingComponents[key].indexOf(matchingPath) === 0) { - return true; - } - } - return false; - } - - const dependencies = []; - Object.keys(transformed.imported).forEach(name => { - if (isCustomComponent(name, transformed.usingComponents)) { - const componentPath = resolve(dirname(resourcePath), name); - dependencies.push({ - name: isFromConstantDir(componentPath) ? name : `${name}?role=component`, // Native miniapp component js file will be loaded by script-loader - options: loaderOptions - }); - } else { - const importedArray = transformed.imported[name]; - let entirePush = false; - importedArray.forEach(importedContent => { - // Component library - if (importedContent.isFromComponentLibrary) { - dependencies.push({ - name, - loader: ScriptLoader, - options: Object.assign({}, loaderOptions, { - importedComponent: importedContent.local - }) - }); - } else { - if (!entirePush) { - dependencies.push({ name }); - entirePush = true; - } - } - }); - } - }); - return [ - `/* Generated by JSX2MP PageLoader, sourceFile: ${this.resourcePath}. */`, - generateDependencies(dependencies), - ].join('\n'); -}; - -function createImportStatement(req) { - return `import '${doubleBackslash(req)}';`; -} - -function generateDependencies(dependencies) { - return dependencies - .map(({ name, loader, options }) => { - let mod = name; - if (loader) mod = loader + '?' + JSON.stringify(options) + '!' + mod; - return createImportStatement(mod); - }) - .join('\n'); -} - diff --git a/packages/jsx2mp-loader/src/script-loader.js b/packages/jsx2mp-loader/src/script-loader.js deleted file mode 100644 index 3951678d2..000000000 --- a/packages/jsx2mp-loader/src/script-loader.js +++ /dev/null @@ -1,291 +0,0 @@ -const { join, dirname, relative, resolve, sep, extname } = require('path'); - -const { copySync, existsSync, mkdirpSync, writeJSONSync, readFileSync, readJSONSync } = require('fs-extra'); -const { getOptions } = require('loader-utils'); -const cached = require('./cached'); -const { removeExt, doubleBackslash, normalizeOutputFilePath, addRelativePathPrefix, isFromTargetDirs } = require('./utils/pathHelper'); -const { isNpmModule, isJSONFile, isTypescriptFile } = require('./utils/judgeModule'); -const isMiniappComponent = require('./utils/isMiniappComponent'); -const parse = require('./utils/parseRequest'); -const output = require('./output'); -const { QUICKAPP } = require('./constants'); - -const ScriptLoader = __filename; - -const MINIAPP_CONFIG_FIELD = 'miniappConfig'; - -module.exports = function scriptLoader(content) { - const query = parse(this.request); - if (query.role) { - return content; - } - - const loaderOptions = getOptions(this); - const { disableCopyNpm, outputPath, mode, entryPath, platform, importedComponent = '', isRelativeMiniappComponent = false, aliasEntries, constantDir } = loaderOptions; - const rootContext = this.rootContext; - const isAppJSon = this.resourcePath === join(rootContext, 'src', 'app.json'); - const isJSON = !isAppJSon && isJSONFile(this.resourcePath); - - const rawContent = isJSON ? content : readFileSync(this.resourcePath, 'utf-8'); - const nodeModulesPathList = getNearestNodeModulesPath(rootContext, this.resourcePath); - const currentNodeModulePath = nodeModulesPathList[nodeModulesPathList.length - 1]; - const rootNodeModulePath = join(rootContext, 'node_modules'); - - const isFromNodeModule = cached(function isFromNodeModule(path) { - return path.indexOf(rootNodeModulePath) === 0; - }); - - const isFromConstantDir = cached(isFromTargetDirs(constantDir)); - - const getNpmFolderName = cached(function getNpmName(relativeNpmPath) { - const isScopedNpm = /^_?@/.test(relativeNpmPath); - return relativeNpmPath.split(sep).slice(0, isScopedNpm ? 2 : 1).join(sep); - }); - - const outputFile = (rawContent, isFromNpm = true) => { - let distSourcePath; - if (isFromNpm) { - const relativeNpmPath = relative(currentNodeModulePath, this.resourcePath); - const splitedNpmPath = relativeNpmPath.split(sep); - if (/^_?@/.test(relativeNpmPath)) splitedNpmPath.shift(); // Extra shift for scoped npm. - splitedNpmPath.shift(); // Skip npm module package, for cnpm/tnpm will rewrite this. - distSourcePath = normalizeNpmFileName(join(outputPath, 'npm', relative(rootNodeModulePath, this.resourcePath))); - } else { - const relativeFilePath = relative( - join(rootContext, dirname(entryPath)), - this.resourcePath - ); - distSourcePath = join(outputPath, relativeFilePath); - } - - let outputContent = {}; - let outputOption = {}; - - outputContent = { code: rawContent }; - outputOption = { - outputPath: { - code: removeExt(distSourcePath) + '.js' - }, - mode, - externalPlugins: [ - [ - require('./babel-plugin-rename-import'), - { normalizeNpmFileName, - distSourcePath, - resourcePath: this.resourcePath, - outputPath, - disableCopyNpm, - platform, - aliasEntries - } - ] - ], - platform, - isTypescriptFile: isTypescriptFile(this.resourcePath) - }; - - output(outputContent, null, outputOption); - }; - - const outputDir = (source, target) => { - if (existsSync(source)) { - mkdirpSync(target); - copySync(source, target, { - overwrite: false, - filter: filename => !/__(mocks|tests?)__/.test(filename) && extname(filename) !== '.json' // JSON file will be written later because usingComponents may be modified - }); - } - }; - - const checkUsingComponents = (dependencies, originalComponentConfigPath, distComponentConfigPath, sourceNativeMiniappScriptFile, npmName) => { - // quickapp component doesn't maintain config file - if (platform.type === QUICKAPP) { - return; - } - if (existsSync(originalComponentConfigPath)) { - const componentConfig = readJSONSync(originalComponentConfigPath); - if (componentConfig.usingComponents) { - for (let key in componentConfig.usingComponents) { - if (componentConfig.usingComponents.hasOwnProperty(key)) { - const componentPath = componentConfig.usingComponents[key]; - if (isNpmModule(componentPath)) { - // component from node module - const realComponentPath = require.resolve(componentPath, { - paths: [this.resourcePath] - }); - const relativeComponentPath = normalizeNpmFileName(addRelativePathPrefix(relative(dirname(sourceNativeMiniappScriptFile), realComponentPath))); - componentConfig.usingComponents[key] = normalizeOutputFilePath(removeExt(relativeComponentPath)); - // Native miniapp component js file will loaded by script-loader - dependencies.push({ - name: realComponentPath, - options: loaderOptions - }); - } else if (componentPath.indexOf('/npm/') === -1) { // Exclude the path that has been modified by jsx-compiler - const absComponentPath = resolve(dirname(sourceNativeMiniappScriptFile), componentPath); - // Native miniapp component js file will loaded by script-loader - dependencies.push({ - name: absComponentPath, - options: Object.assign({ isRelativeMiniappComponent: true }, loaderOptions) - }); - } - } - } - } - if (!existsSync(distComponentConfigPath)) { - writeJSONSync(distComponentConfigPath, componentConfig); - } - } else { - this.emitWarning('Cannot found miniappConfig component for: ' + npmName); - } - }; - - // Third miniapp component may come from npm or constantDir - const isThirdMiniappComponent = isMiniappComponent(this.resourcePath, platform.type); - - if (isFromNodeModule(this.resourcePath)) { - if (disableCopyNpm) { - return isJSON ? '{}' : content; - } - const relativeNpmPath = relative(currentNodeModulePath, this.resourcePath); - const npmFolderName = getNpmFolderName(relativeNpmPath); - const sourcePackagePath = join(currentNodeModulePath, npmFolderName); - const sourcePackageJSONPath = join(sourcePackagePath, 'package.json'); - - const pkg = readJSONSync(sourcePackageJSONPath); - const npmName = pkg.name; // Update to real npm name, for that tnpm will create like `_rax-view@1.0.2@rax-view` folders. - const npmMainPath = join(sourcePackagePath, pkg.main || ''); - - const isUsingMainMiniappComponent = pkg.hasOwnProperty(MINIAPP_CONFIG_FIELD) && this.resourcePath === npmMainPath; - // Is miniapp compatible component. - if (isUsingMainMiniappComponent || isRelativeMiniappComponent || isThirdMiniappComponent) { - const mainName = platform.type === 'ali' ? 'main' : `main:${platform.type}`; - // Case 1: Single component except those old universal api with pkg.miniappConfig - // Case 2: Component library which exports multiple components - const isSingleComponent = pkg.miniappConfig && pkg.miniappConfig[mainName]; - const isComponentLibrary = pkg.miniappConfig && pkg.miniappConfig.subPackages && pkg.miniappConfig.subPackages[importedComponent]; - - const dependencies = []; - - if (isSingleComponent || isComponentLibrary || isRelativeMiniappComponent) { - const miniappComponentPath = isRelativeMiniappComponent ? relative(sourcePackagePath, removeExt(this.resourcePath)) : isSingleComponent ? pkg.miniappConfig[mainName] : pkg.miniappConfig.subPackages[importedComponent][mainName]; - const sourceNativeMiniappScriptFile = join(sourcePackagePath, miniappComponentPath); - - // Exclude quickapp native component for resolving issue - if (platform.type !== QUICKAPP) { - // Native miniapp component js file will loaded by script-loader - dependencies.push({ - name: sourceNativeMiniappScriptFile, - options: loaderOptions - }); - } - - // Handle subComponents - if (isComponentLibrary && pkg.miniappConfig.subPackages[importedComponent].subComponents) { - const subComponents = pkg.miniappConfig.subPackages[importedComponent].subComponents; - Object.keys(subComponents).forEach(subComponentName => { - const subComponentScriptFile = join(sourcePackagePath, subComponents[subComponentName][mainName]); - dependencies.push({ - name: subComponentScriptFile, - loader: ScriptLoader, - options: loaderOptions - }); - }); - } - const miniappComponentDir = miniappComponentPath.slice(0, miniappComponentPath.lastIndexOf('/')); - const source = join(sourcePackagePath, miniappComponentDir); - const target = normalizeNpmFileName(join(outputPath, 'npm', relative(rootNodeModulePath, sourcePackagePath), miniappComponentDir)); - outputDir(source, target); - - // Modify referenced component location according to the platform - const originalComponentConfigPath = join(sourcePackagePath, miniappComponentPath + '.json'); - const distComponentConfigPath = normalizeNpmFileName(join(outputPath, 'npm', relative(rootNodeModulePath, sourcePackagePath), miniappComponentPath + '.json')); - checkUsingComponents(dependencies, originalComponentConfigPath, distComponentConfigPath, sourceNativeMiniappScriptFile, npmName); - } - if (isThirdMiniappComponent) { - const source = dirname(this.resourcePath); - const target = dirname(normalizeNpmFileName(join(outputPath, 'npm', relative(rootNodeModulePath, this.resourcePath)))); - outputDir(source, target); - outputFile(rawContent); - - const originalComponentConfigPath = removeExt(this.resourcePath) + '.json'; - const distComponentConfigPath = normalizeNpmFileName(join(outputPath, 'npm', relative(rootNodeModulePath, removeExt(this.resourcePath) + '.json'))); - checkUsingComponents(dependencies, originalComponentConfigPath, distComponentConfigPath, this.resourcePath, npmName); - } - - return [ - `/* Generated by JSX2MP ScriptLoader, sourceFile: ${this.resourcePath}. */`, - generateDependencies(dependencies), - content - ].join('\n'); - } else { - outputFile(rawContent); - } - } else if (isFromConstantDir(this.resourcePath) && isThirdMiniappComponent) { - const dependencies = []; - outputFile(rawContent, false); - - // Find dependencies according to usingComponents config - const componentConfigPath = removeExt(this.resourcePath) + '.json'; - const componentConfig = readJSONSync(componentConfigPath); - for (let key in componentConfig.usingComponents) { - const componentPath = componentConfig.usingComponents[key]; - const absComponentPath = resolve(dirname(this.resourcePath), componentPath); - dependencies.push({ - name: absComponentPath, - options: loaderOptions - }); - } - return [ - `/* Generated by JSX2MP ScriptLoader, sourceFile: ${this.resourcePath}. */`, - generateDependencies(dependencies), - content - ].join('\n'); - } else { - !isAppJSon && outputFile(rawContent, false); - } - - return isJSON ? '{}' : content; -}; - -/** - * For that alipay build folder can not contain `@`, escape to `_`. - */ -function normalizeNpmFileName(filename) { - const repalcePathname = pathname => pathname.replace(/@/g, '_').replace(/node_modules/g, 'npm'); - - const cwd = process.cwd(); - - if (!filename.includes(cwd)) return repalcePathname(filename); - - // Support for `@` in cwd path - const relativePath = relative(cwd, filename); - return join(cwd, repalcePathname(relativePath)); -} - -function getNearestNodeModulesPath(root, current) { - const relativePathArray = relative(root, current).split(sep); - let index = root; - const result = []; - while (index !== current) { - const ifNodeModules = join(index, 'node_modules'); - if (existsSync(ifNodeModules)) { - result.push(ifNodeModules); - } - index = join(index, relativePathArray.shift()); - } - return result; -} - -function generateDependencies(dependencies) { - return dependencies - .map(({ name, loader, options }) => { - let mod = name; - if (loader) mod = loader + '?' + JSON.stringify(options) + '!' + mod; - return createImportStatement(mod); - }) - .join('\n'); -} - -function createImportStatement(req) { - return `import '${doubleBackslash(req)}';`; -} diff --git a/packages/jsx2mp-loader/src/styleProcessor.js b/packages/jsx2mp-loader/src/styleProcessor.js deleted file mode 100644 index 7f0523f61..000000000 --- a/packages/jsx2mp-loader/src/styleProcessor.js +++ /dev/null @@ -1,64 +0,0 @@ -const { relative, join, dirname, extname } = require('path'); -const sass = require('sass'); -const less = require('less'); -const stylus = require('stylus'); -const stylesheetLoader = require('stylesheet-loader'); - -/** - * convert sass/stylus to css - * - * @param {string} cssType css/sass/scss/stylus - * @param {string} content - * @param {string} filename - * @returns {string} - */ -async function compileCSS(cssType, content, filename) { - let processedContent = content; - switch (cssType) { - case 'sass': - case 'scss': - processedContent = sass.renderSync({ - file: filename - }).css.toString(); - break; - case 'styl': - processedContent = stylus(content) - .set('filename', filename) - .render(); - break; - case 'less': - processedContent = (await less.render(content, { - filename - })).css; - default: - } - return processedContent; -} - -function convertCSSUnit(raw, originExt = 'rem', targetExt = 'rpx') { - const regexp = new RegExp(originExt, 'g'); - return raw.replace(regexp, targetExt); // Maybe could use postcss plugin instead. -} - -function createCSSModule(content) { - const loaderContext = { query: '?log=false' }; - return stylesheetLoader.call(loaderContext, content); -} - -async function processCSS(cssFiles, sourcePath) { - let style = ''; - const assets = {}; - for (let cssFile of cssFiles) { - const cssType = extname(cssFile.filename).slice(1); - cssFile.content = await compileCSS(cssType, cssFile.content, cssFile.filename); - if (cssFile.type === 'cssObject') { - const relativePath = relative(sourcePath, cssFile.filename); - assets[relativePath + '.js'] = createCSSModule(cssFile.content); - } else if (cssFile.type === 'cssFile') { - style += convertCSSUnit(cssFile.content); - } - } - return { style, assets }; -} - -module.exports = processCSS; diff --git a/packages/jsx2mp-loader/src/utils/addSourceMap.js b/packages/jsx2mp-loader/src/utils/addSourceMap.js deleted file mode 100644 index 8092eba84..000000000 --- a/packages/jsx2mp-loader/src/utils/addSourceMap.js +++ /dev/null @@ -1,11 +0,0 @@ -const convertSourceMap = require('convert-source-map'); - -function addSourceMap(code, rawCode, originalMap) { - const map = Object.assign(originalMap, { - sourcesContent: [rawCode] - }); - const sourceMapString = convertSourceMap.fromObject(map).toComment(); - return code + '\n' + sourceMapString; -} - -module.exports = addSourceMap; diff --git a/packages/jsx2mp-loader/src/utils/dce.js b/packages/jsx2mp-loader/src/utils/dce.js deleted file mode 100644 index 909f290ce..000000000 --- a/packages/jsx2mp-loader/src/utils/dce.js +++ /dev/null @@ -1,47 +0,0 @@ -const { transformSync } = require('@babel/core'); - -const parserOpts = { - plugins: [ - 'classProperties', - 'jsx', - 'typescript', - 'trailingFunctionCommas', - 'asyncFunctions', - 'exponentiationOperator', - 'asyncGenerators', - 'objectRestSpread', - ['decorators', { decoratorsBeforeExport: false }], - 'dynamicImport', - ], // support all plugins -}; - -function removeUnusedImport(source) { - return transformSync(source, { - parserOpts, - plugins: [ - [ - require('babel-plugin-danger-remove-unused-import'), - { - ignore: 'rax' - } - ] - ] - }).code; -} - -const codeProcessor = (processors = [], sourceCode) => processors - .filter(processor => typeof processor === 'function') - .reduce( - (prevCode, currProcessor) => currProcessor(prevCode), - sourceCode - ); - -function eliminateDeadCode(source) { - const processors = [ - removeUnusedImport, - ]; - - return codeProcessor(processors, source); -} - -module.exports = eliminateDeadCode; diff --git a/packages/jsx2mp-loader/src/utils/getAliasCorrespondingValue.js b/packages/jsx2mp-loader/src/utils/getAliasCorrespondingValue.js deleted file mode 100644 index 78e0d087b..000000000 --- a/packages/jsx2mp-loader/src/utils/getAliasCorrespondingValue.js +++ /dev/null @@ -1,56 +0,0 @@ -const { join, isAbsolute, relative, dirname } = require('path'); - -const ALIAS_TYPE = { - // react -> rax - MODULE: 1, - // @component/comp.jsx -> /User/name/code/src/component/comp.jsx - PATH: 2, - // @components -> /User/name/code/src/component - COMPLEX_PATH: 3 -}; - -function getAliasType(aliasEntries, importedModule) { - if (aliasEntries[importedModule]) { - if (isAbsolute(aliasEntries[importedModule])) { - return [ALIAS_TYPE.PATH]; - } else { - return [ALIAS_TYPE.MODULE]; - } - } - - let correspondingAlias = ''; - const useComplexPath = Object.keys(aliasEntries).some(alias => { - if (importedModule.startsWith(alias) && importedModule[alias.length] === '/') { - correspondingAlias = alias; - return true; - } - }); - if (useComplexPath) return [ALIAS_TYPE.COMPLEX_PATH, correspondingAlias]; - return []; -} - -function getAliasCorrespondingValue(aliasEntries = {}, value = '', resourcePath = '') { - const [ aliasType, correspondingAlias ] = getAliasType(aliasEntries, value); - if (aliasType) { - let replacedValue; - switch (aliasType) { - case ALIAS_TYPE.MODULE: - // e.g. react -> rax - replacedValue = aliasEntries[value]; - break; - case ALIAS_TYPE.PATH: - // e.g. @logo -> ../components/Logo (alias: @logo -> src/components/Logo) - replacedValue = relative(dirname(resourcePath), aliasEntries[value]); - break; - case ALIAS_TYPE.COMPLEX_PATH: - // e.g. @components/Logo -> ../components/logo (alias: @components -> src/components) - const realAbsolutePath = join(aliasEntries[correspondingAlias], value.replace(correspondingAlias, '')); - replacedValue = './' + relative(dirname(resourcePath), realAbsolutePath); // Add relative path in case the path is recognized as npm package - break; - } - return replacedValue; - } - return null; -} - -module.exports = getAliasCorrespondingValue; diff --git a/packages/jsx2mp-loader/src/utils/isMiniappComponent.js b/packages/jsx2mp-loader/src/utils/isMiniappComponent.js deleted file mode 100644 index 078ed86dc..000000000 --- a/packages/jsx2mp-loader/src/utils/isMiniappComponent.js +++ /dev/null @@ -1,15 +0,0 @@ -const { - existsSync -} = require('fs-extra'); -const { removeExt } = require('./pathHelper'); - -const suffix = { - ali: ['.js', '.json', '.axml'], - wechat: ['.js', '.json', '.wxml'], - bytedance: ['.js', '.json', '.ttml'], - quickapp: ['.ux'], -}; -// e.g file: /root/lib/miniapp/index -module.exports = function(filename, platform = 'ali') { - return suffix[platform].every(s => existsSync(removeExt(filename) + s)); -}; diff --git a/packages/jsx2mp-loader/src/utils/judgeModule.js b/packages/jsx2mp-loader/src/utils/judgeModule.js deleted file mode 100644 index c4e7f6809..000000000 --- a/packages/jsx2mp-loader/src/utils/judgeModule.js +++ /dev/null @@ -1,48 +0,0 @@ -const { extname } = require('path'); - -const WEEX_MODULE_REG = /^@?weex-/; -const QUICKAPP_MODULE_REG = /^@system\./; -const JSX2MP_RUNTIME_MODULE_REG = /^jsx2mp-runtime/; - -function isNpmModule(value) { - return !(value[0] === '.' || value[0] === '/'); -} - -function isWeexModule(value) { - return WEEX_MODULE_REG.test(value); -} - -function isQuickAppModule(value) { - return QUICKAPP_MODULE_REG.test(value); -} - -function isRaxModule(value) { - return value === 'rax'; -} - -function isJsx2mpRuntimeModule(value) { - return JSX2MP_RUNTIME_MODULE_REG.test(value); -} - -function isNodeNativeModule(value) { - return process.binding('natives').hasOwnProperty(value); -} - -function isJSONFile(value) { - return extname(value) === '.json'; -} - -function isTypescriptFile(value) { - return extname(value) === '.ts' || extname(value) === '.tsx'; -} - -module.exports = { - isNpmModule, - isWeexModule, - isQuickAppModule, - isRaxModule, - isJsx2mpRuntimeModule, - isNodeNativeModule, - isJSONFile, - isTypescriptFile -}; diff --git a/packages/jsx2mp-loader/src/utils/minifyCode.js b/packages/jsx2mp-loader/src/utils/minifyCode.js deleted file mode 100644 index 4aa9da61c..000000000 --- a/packages/jsx2mp-loader/src/utils/minifyCode.js +++ /dev/null @@ -1,46 +0,0 @@ -const terser = require('terser'); -const csso = require('csso'); -const prettyData = require('pretty-data').pd; - -function minifyJS(source) { - return terser.minify(source).code; -} - -function minifyCSS(source) { - return csso.minify(source, { - restructure: false - }).css; -} - -function minifyXML(source) { - return prettyData.xmlmin(source); -} - -function minifyJSON(source) { - return prettyData.json(source); -} - -function minify(source, type = '.js') { - if (type === '.js') { - return minifyJS(source); - } - if (type === '.css') { - return minifyCSS(source); - } - if (type === '.json') { - return minifyJSON(source); - } - if (/\..*ml/.test(type)) { - return minifyXML(source); - } - - return source; -} - -module.exports = { - minify, - minifyJS, - minifyCSS, - minifyXML, - minifyJSON -}; diff --git a/packages/jsx2mp-loader/src/utils/parseRequest.js b/packages/jsx2mp-loader/src/utils/parseRequest.js deleted file mode 100644 index 1078e1fab..000000000 --- a/packages/jsx2mp-loader/src/utils/parseRequest.js +++ /dev/null @@ -1,26 +0,0 @@ -function splitOnFirst(str = '', separator = '') { - const separatorIndex = str.indexOf(separator); - if (separatorIndex === -1) { - return []; - } - return [ str.slice(0, separatorIndex), str.slice(separatorIndex + separator.length) ]; -} - -function parse(request = '') { - const lastExclamationMark = request.lastIndexOf('!'); - if (lastExclamationMark) { - const ret = {}; - const originalRequest = request.substr(lastExclamationMark + 1); - const [, queryString] = splitOnFirst(originalRequest, '?'); - if (queryString) { - for (const param of queryString.split('&')) { - const [key, value] = splitOnFirst(param, '='); - ret[key] = value; - } - } - return ret; - } - return {}; -} - -module.exports = parse; diff --git a/packages/jsx2mp-loader/src/utils/pathHelper.js b/packages/jsx2mp-loader/src/utils/pathHelper.js deleted file mode 100644 index b578cd72a..000000000 --- a/packages/jsx2mp-loader/src/utils/pathHelper.js +++ /dev/null @@ -1,117 +0,0 @@ -const { extname, sep, join } = require('path'); - -function removeExt(path, platform) { - const ext = extname(path); - const extReg = new RegExp(`${platform ? `(.${platform})?` : ''}${ext}$`.replace(/\\./g, '\\.')); - return path.replace(extReg, ''); -} - -/** - * judge whether the child dir is part of parent dir - * @param {string} child - * @param {string} parent - */ -function isChildOf(child, parent) { - const childArray = child.split(sep).filter(i => i.length); - const parentArray = parent.split(sep).filter(i => i.length); - const clen = childArray.length; - const plen = parentArray.length; - - let j = 0; - for (let i = 0; i < plen; i++) { - if (parentArray[i] === childArray[j]) { - j++; - } - if (j === clen) { - return true; - } - } - return false; -} - - -/** - * Check whether testPath is from targetDir - * - * @param {string} testPath - * @param {string} targetDir - * @returns {boolean} - */ -function isFromTargetDir(testPath, targetDir) { - return isChildOf(targetDir, testPath); -} - - -/** - * Check whether testPath is from one of the targetDirs - * - * @param {string} testPath - * @returns {Function} - */ -function isFromTargetDirs(targetDirs) { - return (testPath) => { - return targetDirs.some(targetDir => isFromTargetDir(testPath, targetDir)); - }; -} - -/** - * replace the file's extension with new extension - * - * @param {string} filePath - * @param {string} newExtension eg. .ts .js - * @returns {string} - */ -function replaceExtension(filePath, newExtension) { - const lastDot = filePath.lastIndexOf('.'); - return filePath.slice(0, lastDot) + newExtension; -} - -/** - * add double backslashs in case that filePath contains single backslashs - * @param {string} filePath - * @returns {string} - */ -function doubleBackslash(filePath) { - return filePath.replace(/\\/g, '\\\\'); -} - -/** - * Use '/' as path sep regardless of OS when outputting the path to code - * @param {string} filepath - */ -function normalizeOutputFilePath(filepath) { - return filepath.replace(/\\/g, '/'); -} - -/** - * Add ./ at the start of filepath - * @param {string} filepath - * @returns {string} - */ -function addRelativePathPrefix(filepath) { - return filepath[0] !== '.' ? `./${filepath}` : filepath; -} - -/** - * Some packages like jsx-compiler should be a dependency of jsx2mp-loader. But if the project has installed it, then it will take the priority. - * @param {string} packageName - * @param {string} rootDir - */ -function getHighestPriorityPackage(packageName, rootDir) { - const resolvePaths = require.resolve.paths(packageName); - resolvePaths.unshift(join(rootDir, 'node_modules')); - const packagePath = require.resolve(packageName, { - paths: resolvePaths - }); - return require.resolve(packagePath); -} - -module.exports = { - removeExt, - isFromTargetDirs, - replaceExtension, - doubleBackslash, - normalizeOutputFilePath, - addRelativePathPrefix, - getHighestPriorityPackage -}; diff --git a/packages/miniapp-builder-shared/README.md b/packages/miniapp-builder-shared/README.md deleted file mode 100644 index c587e6368..000000000 --- a/packages/miniapp-builder-shared/README.md +++ /dev/null @@ -1,24 +0,0 @@ -### Shared lib for miniapp builder - -#### filterNativePages -It will filter native miniapp pages and return a need copy native page files list. - -#### getAppConfig -It will return a vaild app config for miniapp. - -#### pathHelper -It will export the following methods: - - `relativeModuleResolve` - - `normalizeOutputFilePath` - - `getRelativePath` - - `getDepPath` - - `absoluteModuleResolve` - - `getPlatformExtensions` - - `isNativePage` - - `removeExt` - -#### platformMap -It will return miniapp platform and suffix name correspondence. - -#### getOutputPath -It will return miniapp output path. diff --git a/packages/miniapp-builder-shared/package.json b/packages/miniapp-builder-shared/package.json deleted file mode 100644 index 20bf7108c..000000000 --- a/packages/miniapp-builder-shared/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "miniapp-builder-shared", - "version": "0.1.5", - "description": "miniapp project builder shared lib", - "author": "Rax Team", - "homepage": "https://github.com/alibaba/rax#readme", - "license": "BSD-3-Clause", - "main": "src/index.js", - "directories": { - "lib": "lib", - "test": "__tests__" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/raxjs/rax-scripts.git" - }, - "scripts": { - "test": "echo \"Error: run tests from root\" && exit 1" - }, - "bugs": { - "url": "https://github.com/alibaba/rax/issues" - }, - "dependencies": { - "enhanced-resolve": "^4.3.0", - "fs-extra": "^8.0.1" - } -} diff --git a/packages/miniapp-builder-shared/src/filterNativePages.js b/packages/miniapp-builder-shared/src/filterNativePages.js deleted file mode 100644 index a2146bdc3..000000000 --- a/packages/miniapp-builder-shared/src/filterNativePages.js +++ /dev/null @@ -1,25 +0,0 @@ -const { dirname, join } = require('path'); -const { getDepPath, isNativePage } = require('./pathHelper'); - -/** - * Filter native page - * @param {Array} routes - user routes - * @param {Array} needCopyList - need copy miniapp native pages - * @param {object} options - function options - * @param {string} options.rootDir - project root directory - * @param {string} options.target - user platform - * @returns {Array} - */ -module.exports = (routes, needCopyList, { rootDir, target }) => { - return routes.filter(({ source }) => { - const pageEntry = getDepPath(rootDir, source); - if (isNativePage(pageEntry, target)) { - needCopyList.push({ - from: dirname(join('src', source)), - to: join(target, dirname(source)) - }); - return false; - } - return true; - }); -}; diff --git a/packages/miniapp-builder-shared/src/getAppConfig.js b/packages/miniapp-builder-shared/src/getAppConfig.js deleted file mode 100644 index a85c5b915..000000000 --- a/packages/miniapp-builder-shared/src/getAppConfig.js +++ /dev/null @@ -1,56 +0,0 @@ -const { join, resolve } = require('path'); -const { readJSONSync } = require('fs-extra'); -const getRouteName = require('./utils/getRouteName'); - -const { - relativeModuleResolve, - normalizeOutputFilePath, - getRelativePath -} = require('./pathHelper'); - -module.exports = (rootDir, target, nativeLifeCycleMap) => { - const entryPath = join(rootDir, 'src'); - - const appConfig = readJSONSync(resolve(rootDir, 'src', 'app.json')); - appConfig.pages = []; - const routes = []; - const pagesMap = {}; - - if (!Array.isArray(appConfig.routes)) { - throw new Error('routes in app.json must be array'); - } - - function addPage(route) { - const page = normalizeOutputFilePath( - relativeModuleResolve(entryPath, getRelativePath(route.source)) - ); - appConfig.pages.push(page); - routes.push(route); - pagesMap[route.path] = page; - if (nativeLifeCycleMap) { - nativeLifeCycleMap[resolve(entryPath, route.source)] = {}; - } - } - - appConfig.routes.map(route => { - route.name = route.source; - route.entryName = getRouteName(route, rootDir); - - if (!Array.isArray(route.targets)) { - addPage(route); - } - if (Array.isArray(route.targets) && route.targets.indexOf(target) > -1) { - addPage(route); - } - }); - - if (appConfig.tabBar) { - appConfig.tabBar.items.map(tab => { - tab.path = pagesMap[tab.path]; - }); - } - - appConfig.routes = routes; - - return appConfig; -}; diff --git a/packages/miniapp-builder-shared/src/getOutputPath.js b/packages/miniapp-builder-shared/src/getOutputPath.js deleted file mode 100644 index bc51887fc..000000000 --- a/packages/miniapp-builder-shared/src/getOutputPath.js +++ /dev/null @@ -1,11 +0,0 @@ -const fs = require('fs-extra'); -const path = require('path'); - -module.exports = (context, target) => { - const { rootDir, userConfig } = context; - const { outputDir } = userConfig; - - const output = path.resolve(rootDir, outputDir); - fs.ensureDirSync(output); - return path.resolve(output, target); -}; diff --git a/packages/miniapp-builder-shared/src/index.js b/packages/miniapp-builder-shared/src/index.js deleted file mode 100644 index 295ba8a30..000000000 --- a/packages/miniapp-builder-shared/src/index.js +++ /dev/null @@ -1,13 +0,0 @@ -const filterNativePages = require('./filterNativePages'); -const getAppConfig = require('./getAppConfig'); -const pathHelper = require('./pathHelper'); -const platformMap = require('./platformMap'); -const getOutputPath = require('./getOutputPath'); - -module.exports = { - filterNativePages, - getAppConfig, - pathHelper, - platformMap, - getOutputPath -}; diff --git a/packages/miniapp-builder-shared/src/pathHelper.js b/packages/miniapp-builder-shared/src/pathHelper.js deleted file mode 100644 index 57fdfa365..000000000 --- a/packages/miniapp-builder-shared/src/pathHelper.js +++ /dev/null @@ -1,150 +0,0 @@ -const { join, relative, sep, resolve } = require('path'); -const { existsSync, statSync, readJSONSync } = require('fs-extra'); -const enhancedResolve = require('enhanced-resolve'); -const targetPlatformMap = require('./platformMap'); - -const extensions = ['.js', '.jsx', '.ts', '.tsx']; - -function startsWith(prevString, nextString) { - return prevString.indexOf(nextString) === 0; -} - -function startsWithArr(prevString, nextStringArr = []) { - return nextStringArr.some(nextString => startsWith(prevString, nextString)); -} - -function loadAsFile(module) { - if (existsSync(module) && statSync(module).isFile()) { - return module; - } - for (let e of extensions) { - if (existsSync(module + e) && statSync(module + e).isFile()) { - return module; - } - } -} - -function loadAsDirectory(module) { - if (!existsSync(module)) { - return; - } - let stat = statSync(module); - if (stat.isDirectory()) { - for (let e of extensions) { - const indexFile = join(module, `index${e}`); - if (existsSync(indexFile) && statSync(indexFile).isFile()) { - return join(module, 'index'); - } - } - } else if (stat.isFile()) { - return loadAsFile(module); - } -} - -/** - * Resolve relative path. - * @param {string} script - * @param {string} dependency - * @return {string} - */ -function relativeModuleResolve(script, dependency) { - if (startsWithArr(dependency, ['./', '../', '/', '.\\', '..\\', '\\'])) { - let dependencyPath = join(script, dependency); - return relative( - script, - loadAsFile(dependencyPath) || loadAsDirectory(dependencyPath) - ); - } else throw new Error('The page source path does not meet the requirements'); -}; - -/** - * Use '/' as path sep regardless of OS when outputting the path to code - * @param {string} filepath - */ -function normalizeOutputFilePath(filepath) { - return filepath.replace(/\\/g, '/'); -} - -function getRelativePath(filePath) { - let relativePath; - if (filePath[0] === sep) { - relativePath = `.${filePath}`; - } else if (filePath[0] === '.') { - relativePath = filePath; - } else { - relativePath = `.${sep}${filePath}`; - } - return relativePath; -} - -/** - * ./pages/foo -> based on src, return original - * /pages/foo -> based on rootContext - * pages/foo -> based on src, add prefix: './' or '.\' - */ -function getDepPath(rootDir, source, sourcePath = 'src') { - if (source[0] === sep || source[0] === '.') { - return join(rootDir, sourcePath, source); - } else { - return resolve(rootDir, sourcePath, source); - } -} - -/** - * Resolve absolute path - * @param {...any} files - */ -function absoluteModuleResolve(...files) { - return enhancedResolve.create.sync({ - extensions: ['.ts', '.js', '.tsx', '.jsx', '.json'] - })(...files); -} - -/** - * get more specific files in miniapp - * @param {string} platform - * @param {string[]} extensions - */ -function getPlatformExtensions(platform, extensions = []) { - return [ - ...platform ? extensions.map((ext) => `.${platform}${ext}`) : [], - ...extensions, - ]; -} - -/** - * Judge whether the file is a native page according to the existence of the template file - * @param {string} filePath - * @param {string} target - */ -function isNativePage(filePath, target) { - if (existsSync(filePath + targetPlatformMap[target].extension.xml)) { - try { - const jsonContent = readJSONSync(`${filePath}.json`); - return !jsonContent.component; - } catch (e) {} - // If json file doesn't exist or not declare component: true, then it's a native page - return true; - } - return false; -} - -/** - * Remove file extension - * @param {string} filePath - */ -function removeExt(filePath) { - const lastDot = filePath.lastIndexOf('.'); - return lastDot === -1 ? filePath : filePath.slice(0, lastDot); -} - -module.exports = { - relativeModuleResolve, - normalizeOutputFilePath, - getRelativePath, - getDepPath, - absoluteModuleResolve, - getPlatformExtensions, - isNativePage, - removeExt -}; diff --git a/packages/miniapp-builder-shared/src/platformMap.js b/packages/miniapp-builder-shared/src/platformMap.js deleted file mode 100644 index 98ff8810f..000000000 --- a/packages/miniapp-builder-shared/src/platformMap.js +++ /dev/null @@ -1,36 +0,0 @@ -const { MINIAPP, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, QUICKAPP } = require('./utils/constants'); - -module.exports = { - [MINIAPP]: { - type: 'ali', - name: 'Alibaba MiniApp', - extension: { - xml: '.axml', - css: '.acss', - } - }, - [WECHAT_MINIPROGRAM]: { - type: 'wechat', - name: 'WeChat MiniProgram', - extension: { - xml: '.wxml', - css: '.wxss', - } - }, - [BYTEDANCE_MICROAPP]: { - type: 'bytedance', - name: 'ByteDance MicroApp', - extension: { - xml: '.ttml', - css: '.ttss' - } - }, - [QUICKAPP]: { - type: 'quickapp', - name: 'QuickApp', - extension: { - xml: '.ux', - css: '.css', - } - }, -}; diff --git a/packages/miniapp-builder-shared/src/utils/constants.js b/packages/miniapp-builder-shared/src/utils/constants.js deleted file mode 100644 index 098401941..000000000 --- a/packages/miniapp-builder-shared/src/utils/constants.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - MINIAPP: 'miniapp', - WECHAT_MINIPROGRAM: 'wechat-miniprogram', - BYTEDANCE_MICROAPP: 'bytedance-microapp', - QUICKAPP: 'quickapp', -}; diff --git a/packages/miniapp-builder-shared/src/utils/getRouteName.js b/packages/miniapp-builder-shared/src/utils/getRouteName.js deleted file mode 100644 index 026c8d883..000000000 --- a/packages/miniapp-builder-shared/src/utils/getRouteName.js +++ /dev/null @@ -1,27 +0,0 @@ -const path = require('path'); -const fs = require('fs-extra'); - -module.exports = (route, rootDir) => { - if (route.name) { - return route.name; - } - - const appConfig = fs.readJsonSync(path.resolve(rootDir, 'src/app.json')); - - const routeName = appConfig.routeName ? appConfig.routeName : 'path'; - - if (routeName === 'path') { - return route.source.replace(/\//g, '_'); - } - - if (routeName === 'pages') { - try { - // get Home from pages/Home/index or pages/Home - const name = route.source.match(/pages\/([^/]*)/); - return name[1]; - } catch (e) { - console.error('"routeName": "pages" mode request routes in /pages directory'); - process.exit(1); - } - } -}; diff --git a/packages/miniapp-compile-config/README.md b/packages/miniapp-compile-config/README.md deleted file mode 100644 index 11ad5e05f..000000000 --- a/packages/miniapp-compile-config/README.md +++ /dev/null @@ -1,56 +0,0 @@ -### miniapp-compile-config -小程序编译时工程公共配置设置。 - -### 方法 -#### setAppConfig -##### 参数 - -| 参数 | 类型 | 默认值 | 必填 | 描述 | -| ---------- | ------ | ------ | ---- | ------------------------------------------------------------ | -| config | object | - | ✔️ | webpack chain config | -| userConfig | object | {} | ✘ | 当前小程序平台的用户配置,例如 `{ nativeConfig: { appId: 123 } }` | -| options | object | - | ✔️ | options 子项见下表 - - -##### options 子项 - -| 参数 | 类型 | 默认值 | 必填 | 描述 | -| ------------- | ------ | ------ | ---- | ------------------------------------------------------------ | -| context | object | - | ✔️ | build plugin 上下文变量,包含运行时的各种环境信息 | -| target | string | - | ✔️ | 构建的小程序平台类型,例如 `miniapp`/`wechat-miniprogram` | -| onGetWebpackConfig | function | - | ✔️ | 在工程获取 webpack 时触发的函数,可以在 build plugin 的 api 中获取 | -| entryPath | string | - | ✔️ | 入口路径 | -| outputPath | string | - | ✔️ | 输出路径 | - - -#### setComponentConfig -##### 参数 - -| 参数 | 类型 | 默认值 | 必填 | 描述 | -| ---------- | ------ | ------ | ---- | ------------------------------------------------------------ | -| config | object | - | ✔️ | webpack chain config | -| userConfig | object | {} | ✘ | 当前小程序平台的用户配置,例如 `{ nativeConfig: { appId: 123 } }` | -| options | object | - | ✔️ | options 子项见下表 - - -##### options 子项 - -| 参数 | 类型 | 默认值 | 必填 | 描述 | -| ------------- | ------ | ------ | ---- | ------------------------------------------------------------ | -| context | object | - | ✔️ | build plugin 上下文变量,包含运行时的各种环境信息 | -| target | string | - | ✔️ | 构建的小程序平台类型,例如 `miniapp`/`wechat-miniprogram` | -| onGetWebpackConfig | function | - | ✔️ | 在工程获取 webpack 时触发的函数,可以在 build plugin 的 api 中获取 | -| entryPath | string | - | ✔️ | 入口路径 | -| outputPath | string | - | ✔️ | 输出路径 | - -### 使用 - -```js -const { setAppConfig, setComponentConfig } = require('miniapp-compile-config'); - -// 应用 -setAppConfig(config, userConfig, { context, target, onGetWebpackConfig, entryPath, outputPath }); - -// 组件 -setComponentConfig(config, userConfig, { context, target, onGetWebpackConfig, entryPath, outputPath }); -``` diff --git a/packages/miniapp-compile-config/package.json b/packages/miniapp-compile-config/package.json deleted file mode 100644 index 3c97f7372..000000000 --- a/packages/miniapp-compile-config/package.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "miniapp-compile-config", - "version": "0.1.2", - "description": "miniapp compile project config", - "author": "Rax Team", - "homepage": "https://github.com/alibaba/rax#readme", - "license": "BSD-3-Clause", - "main": "src/index.js", - "directories": { - "lib": "lib", - "test": "__tests__" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/raxjs/rax-scripts.git" - }, - "scripts": { - "test": "echo \"Error: run tests from root\" && exit 1" - }, - "bugs": { - "url": "https://github.com/alibaba/rax/issues" - }, - "peerDependencies": { - "webpack": "^4.0.0" - }, - "dependencies": { - "chokidar": "^3.4.2", - "copy-webpack-plugin": "^6.0.3", - "fs-extra": "^8.0.1", - "json-loader": "^0.5.7", - "jsx2mp-loader": "^0.4.13", - "memory-fs": "^0.5.0", - "miniapp-builder-shared": "^0.1.0", - "rax-compile-config": "^0.2.15", - "rax-miniapp-babel-plugins": "^0.1.3", - "rax-miniapp-config-webpack-plugin": "^1.2.3", - "rax-miniapp-runtime-webpack-plugin": "^1.1.0", - "terser": "^4.8.0", - "ts-loader": "^8.0.3", - "webpack": "^4.44.1" - } -} diff --git a/packages/miniapp-compile-config/src/index.js b/packages/miniapp-compile-config/src/index.js deleted file mode 100644 index 4151eab70..000000000 --- a/packages/miniapp-compile-config/src/index.js +++ /dev/null @@ -1,2 +0,0 @@ -exports.setAppConfig = require('./setAppConfig'); -exports.setComponentConfig = require('./setComponentConfig'); diff --git a/packages/miniapp-compile-config/src/plugins/CopyJsx2mpRuntime.js b/packages/miniapp-compile-config/src/plugins/CopyJsx2mpRuntime.js deleted file mode 100644 index 827195dd4..000000000 --- a/packages/miniapp-compile-config/src/plugins/CopyJsx2mpRuntime.js +++ /dev/null @@ -1,65 +0,0 @@ -const { join } = require('path'); -const { copySync, existsSync, writeFileSync, readJSONSync, readFileSync } = require('fs-extra'); -const { minify } = require('terser'); - -/** - * Runtime packages should be a dependency of build-plugin-rax-app. But if the project has installed it, then it will take the priority. - * @param {string} packageName - * @param {string} rootDir - */ -function getHighestPriorityPackageJSON(packageName, rootDir) { - const targetFile = join(packageName, 'package.json'); - const resolvePaths = require.resolve.paths(targetFile); - resolvePaths.unshift(join(rootDir, 'node_modules')); - const packageJSONPath = require.resolve(targetFile, { - paths: resolvePaths - }); - return packageJSONPath; -} - -const runtime = 'jsx2mp-runtime'; -let runtimePackageJSONPath = null; -let runtimePackageJSON = null; -let runtimePackagePath = null; - -/** - * For convenient to copy vendors. - */ -module.exports = class JSX2MPRuntimePlugin { - constructor({ platform = 'ali', mode = 'build', rootDir = '', outputPath = '' }) { - this.platform = platform; - this.mode = mode; - this.rootDir = rootDir; - this.outputPath = outputPath; - } - - apply(compiler) { - compiler.hooks.emit.tapAsync( - 'JSX2MPRuntimePlugin', - (compilation, callback) => { - if (!runtimePackageJSONPath) { - runtimePackageJSONPath = getHighestPriorityPackageJSON(runtime, this.rootDir); - runtimePackageJSON = readJSONSync(runtimePackageJSONPath); - runtimePackagePath = join(runtimePackageJSONPath, '..'); - } - - const runtimeTargetPath = runtimePackageJSON.miniprogram && runtimePackageJSON.miniprogram[this.platform] - ? runtimePackageJSON.miniprogram[this.platform] - : runtimePackageJSON.main || 'index.js'; - const sourceFile = require.resolve(join(runtimePackagePath, runtimeTargetPath)); - const targetFile = join(this.outputPath, 'npm', runtime + '.js'); - - if (this.mode === 'build') { - const sourceCode = minify(readFileSync(sourceFile, 'utf-8')).code; - writeFileSync(targetFile, sourceCode); - } else { - if (!existsSync(targetFile)) { - copySync(sourceFile, targetFile); - } - } - - callback(); - } - ); - } -}; diff --git a/packages/miniapp-compile-config/src/plugins/CopyPublicFile.js b/packages/miniapp-compile-config/src/plugins/CopyPublicFile.js deleted file mode 100644 index 9e84fed6b..000000000 --- a/packages/miniapp-compile-config/src/plugins/CopyPublicFile.js +++ /dev/null @@ -1,57 +0,0 @@ -const { resolve } = require('path'); -const { copySync } = require('fs-extra'); -const chokidar = require('chokidar'); -const { pathHelper: { isNativePage, removeExt } } = require('miniapp-builder-shared'); - -/** - * Copy directories from rootDir + `src/${dir}` to outputPath + `${dir}` - * @param {string[]} constantDir - * @param {string} rootDir - * @param {string} outputPath - */ -function copyPublicFile(constantDir, rootDir, outputPath, target) { - for (let srcDir of constantDir) { - const srcPath = resolve(rootDir, srcDir); - const distPath = resolve(outputPath, srcDir.split('/').slice(1).join('/')); - copySync(srcPath, distPath, { - filter: (file) => { - if (/\.js$/.test(file)) { - return isNativePage(removeExt(file), target); - } - return true; - } - }); - } -} - -/** - * Copy public directories to dist - */ -module.exports = class CopyPublicFilePlugin { - constructor({ mode = 'build', rootDir = '', outputPath = '', constantDir = [], target }) { - this.mode = mode; - this.rootDir = rootDir; - this.outputPath = outputPath; - this.constantDir = constantDir; - this.target = target; - } - - apply(compiler) { - compiler.hooks.emit.tapAsync( - 'CopyPublicFilePlugin', - (compilation, callback) => { - if (this.mode === 'build') { - copyPublicFile(this.constantDir, this.rootDir, this.outputPath, this.target); - } else { - const constantDirectoryPaths = this.constantDir.map(dirPath => resolve(this.rootDir, dirPath)); - const watcher = chokidar.watch(constantDirectoryPaths); - watcher.on('all', () => { - copyPublicFile(this.constantDir, this.rootDir, this.outputPath, this.target); - }); - } - - callback(); - } - ); - } -}; diff --git a/packages/miniapp-compile-config/src/plugins/ModifyOutputFileSystem.js b/packages/miniapp-compile-config/src/plugins/ModifyOutputFileSystem.js deleted file mode 100644 index 8abb306df..000000000 --- a/packages/miniapp-compile-config/src/plugins/ModifyOutputFileSystem.js +++ /dev/null @@ -1,7 +0,0 @@ -const MemFs = require('memory-fs'); - -module.exports = class ModifyOutputFileSystemPlugin { - apply(compiler) { - compiler.outputFileSystem = new MemFs(); - } -}; diff --git a/packages/miniapp-compile-config/src/setAppConfig.js b/packages/miniapp-compile-config/src/setAppConfig.js deleted file mode 100644 index 77f9a73ff..000000000 --- a/packages/miniapp-compile-config/src/setAppConfig.js +++ /dev/null @@ -1,130 +0,0 @@ -const { dirname, resolve } = require('path'); -const { - platformMap, - filterNativePages, - getAppConfig, -} = require('miniapp-builder-shared'); -const { existsSync } = require('fs-extra'); - -const MiniAppConfigPlugin = require('rax-miniapp-config-webpack-plugin'); - -const AppLoader = require.resolve('jsx2mp-loader/src/app-loader'); -const PageLoader = require.resolve('jsx2mp-loader/src/page-loader'); - -const setBaseConfig = require('./setBaseConfig'); -const setEntry = require('./setEntry'); - -module.exports = ( - config, - userConfig = {}, - { onGetWebpackConfig, context, target, entryPath, outputPath } -) => { - const platformInfo = platformMap[target]; - const { - mode = 'build', - disableCopyNpm = false, - turnOffSourceMap = false, - constantDir = [] - } = userConfig; - const { rootDir } = context; - - const appConfig = getAppConfig(rootDir, target); - - setEntry(config, appConfig.routes, { entryPath, rootDir, target }); - - // Need Copy files or dir - const needCopyList = []; - const loaderParams = { - mode, - entryPath, - outputPath, - disableCopyNpm, - turnOffSourceMap, - platform: platformInfo, - }; - - // Set constantDir - // `public` directory is the default static resource directory - const isPublicFileExist = existsSync(resolve(rootDir, 'src/public')); - - // To make old `constantDir` param compatible - loaderParams.constantDir = isPublicFileExist - ? ['src/public'].concat(constantDir) - : constantDir; - - appConfig.routes = filterNativePages(appConfig.routes, needCopyList, { - rootDir, - target, - outputPath, - }); - - const pageLoaderParams = { - ...loaderParams, - entryPath, - }; - - const appLoaderParams = { - ...loaderParams, - entryPath: dirname(entryPath), - }; - - config.cache(true).mode('production').target('node'); - - // Set base jsx2mp config - setBaseConfig(config, userConfig, { - onGetWebpackConfig, - entryPath, - context, - loaderParams, - target, - outputPath, - }); - - needCopyList.forEach((dirPatterns) => - loaderParams.constantDir.push(dirPatterns.from) - ); - - // Add app and page jsx2mp loader - config.module - .rule('withRoleJSX') - .use('app') - .loader(AppLoader) - .options(appLoaderParams) - .end() - .use('page') - .loader(PageLoader) - .options(pageLoaderParams) - .end(); - - config.plugin('miniAppConfig').use(MiniAppConfigPlugin, [ - { - type: 'complie', - appConfig, - getAppConfig, - outputPath, - target, - nativeConfig: userConfig.nativeConfig, - }, - ]); - - onGetWebpackConfig(target, (config) => { - const aliasEntries = config.resolve.alias.entries(); - config.module - .rule('withRoleJSX') - .use('app') - .tap(appLoaderParams => { - return { - ...appLoaderParams, - aliasEntries - }; - }) - .end() - .use('page') - .tap(pageLoaderParams => { - return { - ...pageLoaderParams, - aliasEntries - }; - }); - }); -}; diff --git a/packages/miniapp-compile-config/src/setBaseConfig.js b/packages/miniapp-compile-config/src/setBaseConfig.js deleted file mode 100644 index 7a7d60868..000000000 --- a/packages/miniapp-compile-config/src/setBaseConfig.js +++ /dev/null @@ -1,169 +0,0 @@ -const webpack = require('webpack'); - -const ComponentLoader = require.resolve('jsx2mp-loader/src/component-loader'); -const ScriptLoader = require.resolve('jsx2mp-loader/src/script-loader'); -const FileLoader = require.resolve('jsx2mp-loader/src/file-loader'); -const { - platformMap, - pathHelper: { getPlatformExtensions }, -} = require('miniapp-builder-shared'); - -const ModifyOutputFileSystemPlugin = require('./plugins/ModifyOutputFileSystem'); -const CopyJsx2mpRuntimePlugin = require('./plugins/CopyJsx2mpRuntime'); -const CopyPublicFilePlugin = require('./plugins/CopyPublicFile'); - -module.exports = ( - config, - userConfig, - { context, onGetWebpackConfig, entryPath, outputPath, loaderParams, target } -) => { - const platformInfo = platformMap[target]; - const { rootDir } = context; - const { - platform = platformInfo.type, - mode = 'build' - } = userConfig; - - // Set alias - config.resolve.alias.clear(); - config.resolve.alias.set('react', 'rax').set('react-dom', 'rax-dom'); - onGetWebpackConfig(target, (config) => { - const aliasEntries = config.resolve.alias.entries(); - loaderParams.aliasEntries = aliasEntries; - }); - - // Clear prev rules - config.module.rule('jsx').uses.clear(); - config.module.rule('tsx').uses.clear(); - - config.module - .rule('tsx') - .test(/\.(tsx?)$/) - .use('ts') - .loader(require.resolve('ts-loader')) - .options({ - transpileOnly: true, - }); - - // Remove all app.json before it - config.module.rule('appJSON').uses.clear(); - - config - .cache(true) - .mode('production') - .target('node'); - - config.module - .rule('withRoleJSX') - .test(/\.t|jsx?$/) - .enforce('post') - .exclude.add(/node_modules/) - .end() - .use('component') - .loader(ComponentLoader) - .options({ - ...loaderParams, - entryPath, - }) - .end() - .use('platform') - .loader(require.resolve('rax-compile-config/src/platformLoader')) - .options({ platform: target }) - .end() - .use('script') - .loader(ScriptLoader) - .options(loaderParams) - .end(); - - config.module - .rule('npm') - .test(/\.js$/) - .include.add(/node_modules/) - .end() - .use('script') - .loader(ScriptLoader) - .options(loaderParams) - .end(); - - config.module - .rule('staticFile') - .test(/\.(bmp|webp|svg|png|webp|jpe?g|gif)$/i) - .use('file') - .loader(FileLoader) - .options({ - entryPath, - outputPath, - }); - - // Exclude app.json - config.module - .rule('json') - .test(/\.json$/) - .use('script-loader') - .loader(ScriptLoader) - .options(loaderParams) - .end() - .use('json-loader') - .loader(require.resolve('json-loader')); - - // Distinguish end construction - config.resolve.extensions - .clear() - .merge( - getPlatformExtensions(platform, ['.js', '.jsx', '.ts', '.tsx', '.json']) - ); - - config.resolve.mainFields.add('main').add('module'); - - config.externals([ - function(ctx, request, callback) { - if (/\.(css|sass|scss|styl|less)$/.test(request)) { - return callback(null, `commonjs2 ${request}`); - } - if (/^@weex-module\//.test(request)) { - return callback(null, `commonjs2 ${request}`); - } - // compatible with @system for quickapp - if (request.indexOf('@system') !== -1) { - return callback(null, `commonjs ${request}`); - } - // compatible with plugin with miniapp plugin - if (/^plugin\:\/\//.test(request)) { - return callback(null, `commonjs ${request}`); - } - callback(); - }, - ]); - - config.plugin('define').use(webpack.DefinePlugin, [ - { - 'process.env': { - NODE_ENV: mode === 'build' ? '"production"' : '"development"', - }, - }, - ]); - - config - .plugin('watchIgnore') - .use(webpack.WatchIgnorePlugin, [[/node_modules/]]); - - config.plugin('modifyOutputFileSystem').use(ModifyOutputFileSystemPlugin); - - if (loaderParams.constantDir.length > 0) { - config.plugin('copyPublicFile').use(CopyPublicFilePlugin, [ - { - mode, - outputPath, - rootDir, - constantDir: loaderParams.constantDir, - target, - }, - ]); - } - - if (!loaderParams.disableCopyNpm) { - config - .plugin('runtime') - .use(CopyJsx2mpRuntimePlugin, [{ platform, mode, outputPath, rootDir }]); - } -}; diff --git a/packages/miniapp-compile-config/src/setComponentConfig.js b/packages/miniapp-compile-config/src/setComponentConfig.js deleted file mode 100644 index e660b5afc..000000000 --- a/packages/miniapp-compile-config/src/setComponentConfig.js +++ /dev/null @@ -1,49 +0,0 @@ -const { platformMap } = require('miniapp-builder-shared'); -const { existsSync } = require('fs-extra'); -const { resolve } = require('path'); -const setBaseConfig = require('./setBaseConfig'); - -module.exports = ( - config, - userConfig = {}, - { onGetWebpackConfig, context, target, entryPath, outputPath } -) => { - const platformInfo = platformMap[target]; - const { - mode = 'build', - disableCopyNpm = mode === 'build', - turnOffSourceMap = false, - constantDir = [] - } = userConfig; - const { rootDir } = context; - - const loaderParams = { - mode, - entryPath, - outputPath, - disableCopyNpm, - turnOffSourceMap, - platform: platformInfo, - }; - - config.entryPoints.clear(); - config.entry('component').add(`./${entryPath}?role=component`); - - // Set constantDir - // `public` directory is the default static resource directory - const isPublicFileExist = existsSync(resolve(rootDir, 'src/public')); - - // To make old `constantDir` param compatible - loaderParams.constantDir = isPublicFileExist - ? ['src/public'].concat(constantDir) - : constantDir; - - setBaseConfig(config, userConfig, { - context, - onGetWebpackConfig, - entryPath, - outputPath, - loaderParams, - target, - }); -}; diff --git a/packages/miniapp-compile-config/src/setEntry.js b/packages/miniapp-compile-config/src/setEntry.js deleted file mode 100644 index c2a123fa1..000000000 --- a/packages/miniapp-compile-config/src/setEntry.js +++ /dev/null @@ -1,33 +0,0 @@ -const { dirname } = require('path'); -const { - pathHelper: { absoluteModuleResolve, getDepPath }, -} = require('miniapp-builder-shared'); - -function getEntry(entryAppFilePath, routes, rootDir) { - const sourcePath = dirname(entryAppFilePath); - const entry = {}; - - entry.app = - absoluteModuleResolve(rootDir, `./${entryAppFilePath}`) + '?role=app'; // Mark it as app file - - if (Array.isArray(routes)) { - routes.forEach(({ source: pageSource }) => { - entry[`page@${pageSource}`] = `${getDepPath( - rootDir, - pageSource, - sourcePath - )}?role=page`; // Mark it as page file - }); - } - return entry; -} - -module.exports = (config, routes, options) => { - config.entryPoints.clear(); - const { entryPath, rootDir } = options; - const entries = getEntry(entryPath, routes, rootDir); - for (const [entryName, source] of Object.entries(entries)) { - const entryConfig = config.entry(entryName); - entryConfig.add(source); - } -}; diff --git a/packages/miniapp-runtime-config/README.md b/packages/miniapp-runtime-config/README.md deleted file mode 100644 index a631ae36d..000000000 --- a/packages/miniapp-runtime-config/README.md +++ /dev/null @@ -1,27 +0,0 @@ -### miniapp-runtime-config -小程序运行时工程公共配置设置。 - -### 参数 - -| 参数 | 类型 | 默认值 | 必填 | 描述 | -| ---------- | ------ | ------ | ---- | ------------------------------------------------------------ | -| config | object | - | ✔️ | webpack chain config | -| userConfig | object | {} | ✘ | 当前小程序平台的用户配置,例如 `{ nativeConfig: { appId: 123 } }` | -| options | object | - | ✔️ | options 子项见下表 | - - -#### options 子项 - -| 参数 | 类型 | 默认值 | 必填 | 描述 | -| ------------- | ------ | ------ | ---- | ------------------------------------------------------------ | -| context | object | - | ✔️ | build plugin 上下文变量,包含运行时的各种环境信息 | -| target | string | - | ✔️ | 构建的小程序平台类型,例如 `miniapp`/`wechat-miniprogram` | -| babelRuleName | string | babel | ✘ | webpack chain config 中设置的 babel-loader 规则别名,例如 `config.rule('jsx').use('babel').loader(require.resolve('babel-loader'))`,此时 `babelRuleName` 值为 `babel` | - -### 使用 - -```js -const { setConfig } = require('miniapp-runtime-config'); - -setConfig(config, userConfig, { context, target, babelRuleName }); -``` diff --git a/packages/miniapp-runtime-config/package.json b/packages/miniapp-runtime-config/package.json deleted file mode 100644 index 8a077dd64..000000000 --- a/packages/miniapp-runtime-config/package.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "miniapp-runtime-config", - "version": "0.1.1", - "description": "miniapp runtime project config", - "author": "Rax Team", - "homepage": "https://github.com/alibaba/rax#readme", - "license": "BSD-3-Clause", - "main": "src/index.js", - "directories": { - "lib": "lib", - "test": "__tests__" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/raxjs/rax-scripts.git" - }, - "scripts": { - "test": "echo \"Error: run tests from root\" && exit 1" - }, - "bugs": { - "url": "https://github.com/alibaba/rax/issues" - }, - "peerDependencies": { - "webpack": "^4.0.0" - }, - "dependencies": { - "copy-webpack-plugin": "^6.0.3", - "miniapp-builder-shared": "^0.1.0", - "rax-miniapp-babel-plugins": "^0.1.3", - "rax-miniapp-config-webpack-plugin": "^1.2.3", - "rax-miniapp-runtime-webpack-plugin": "^1.1.0", - "miniapp-render": "^1.2.2" - } -} diff --git a/packages/miniapp-runtime-config/src/index.js b/packages/miniapp-runtime-config/src/index.js deleted file mode 100644 index f9411557d..000000000 --- a/packages/miniapp-runtime-config/src/index.js +++ /dev/null @@ -1 +0,0 @@ -exports.setConfig = require('./setConfig'); diff --git a/packages/miniapp-runtime-config/src/setConfig.js b/packages/miniapp-runtime-config/src/setConfig.js deleted file mode 100644 index c1235e549..000000000 --- a/packages/miniapp-runtime-config/src/setConfig.js +++ /dev/null @@ -1,99 +0,0 @@ -const { getAppConfig, filterNativePages, getOutputPath } = require('miniapp-builder-shared'); -const getMiniAppBabelPlugins = require('rax-miniapp-babel-plugins'); -const MiniAppRuntimePlugin = require('rax-miniapp-runtime-webpack-plugin'); -const MiniAppConfigPlugin = require('rax-miniapp-config-webpack-plugin'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); - -/** - * Set miniapp runtime project webpack config - * @param {object} config - webpack config chain - * @param {object} userConfig - user config for miniapp - * @param {object} options - * @param {object} options.context - webpack context - * @param {string} options.target - miniapp platform - * @param {string} options.babelRuleName - babel loader name in webpack chain - */ -module.exports = (config, userConfig, { context, target, babelRuleName = 'babel', onGetWebpackConfig }) => { - const { rootDir, command } = context; - // Get miniapp output path - const outputPath = getOutputPath(context, target); - // Using components - const usingComponents = {}; - // Native lifecycle map - const nativeLifeCycleMap = {}; - - // Using plugins - const usingPlugins = {}; - - // Need Copy files or dir - const needCopyList = []; - - const appConfig = getAppConfig(rootDir, target, nativeLifeCycleMap); - appConfig.routes = filterNativePages(appConfig.routes, needCopyList, { rootDir, target, outputPath }); - - config.output.filename(`${target}/common/[name].js`); - - ['jsx', 'tsx'].forEach(ruleName => { - config.module.rule(ruleName) - .use(babelRuleName) - .tap(options => { - options.presets = [ - ...options.presets, - { - plugins: getMiniAppBabelPlugins({ - usingComponents, - nativeLifeCycleMap, - target, - rootDir, - usingPlugins, - runtimeDependencies: userConfig.runtimeDependencies, - }) - } - ]; - return options; - }); - }); - - config.plugin('MiniAppConfigPlugin').use(MiniAppConfigPlugin, [ - { - type: 'runtime', - appConfig, - outputPath, - target, - getAppConfig, - nativeConfig: userConfig.nativeConfig - } - ]); - config.plugin('MiniAppRuntimePlugin').use(MiniAppRuntimePlugin, [ - { - ...appConfig, - target, - config: userConfig, - usingComponents, - nativeLifeCycleMap, - rootDir, - command, - usingPlugins, - needCopyList - } - ]); - - if (needCopyList.length > 0) { - config.plugin('copyWebpackPluginForRuntimeMiniapp') - .use(CopyWebpackPlugin, [{ - patterns: needCopyList - }]); - } - - config.devServer.writeToDisk(true).noInfo(true).inline(false); - config.devtool('none'); - - // publicPath should not work in miniapp, just keep default value - onGetWebpackConfig(target, (config) => { - config.output.publicPath('/'); - }); - - if (command === 'start') { - config.devtool('inline-source-map'); - } -}; diff --git a/packages/platform-loader/src/TraverseImport.js b/packages/platform-loader/src/TraverseImport.js index f10ecfe52..74abe2533 100644 --- a/packages/platform-loader/src/TraverseImport.js +++ b/packages/platform-loader/src/TraverseImport.js @@ -58,8 +58,8 @@ module.exports = function traverseImport(options, inputSource, sourceMapOption) const propertyMap = {}; Object.keys(platformMap).forEach((p) => { - let keys = platformMap[p]; - for (let key of keys) { + const keys = platformMap[p]; + for (const key of keys) { if (!propertyMap[key]) { propertyMap[key] = p === platformName; } @@ -105,8 +105,8 @@ module.exports = function traverseImport(options, inputSource, sourceMapOption) const location = { start: { line: err.loc.line, - column: err.loc.column + 1 - } + column: err.loc.column + 1, + }, }; // remove trailing "(LINE:COLUMN)" acorn message and add in esprima syntax error message start @@ -158,7 +158,7 @@ module.exports = function traverseImport(options, inputSource, sourceMapOption) const { node } = path; if (options.name.indexOf(node.source.value) !== -1) { - node.specifiers.forEach(spec => { + node.specifiers.forEach((spec) => { if (spec.type === 'ImportNamespaceSpecifier') { specified.push({ local: spec.local.name, @@ -173,7 +173,7 @@ module.exports = function traverseImport(options, inputSource, sourceMapOption) }); if (hasPlatformSpecified) { - specified.forEach(specObj => { + specified.forEach((specObj) => { if (specObj.imported === '*') { path.insertAfter(types.VariableDeclaration( 'const', [ diff --git a/packages/platform-loader/src/index.js b/packages/platform-loader/src/index.js index 07549f9f6..1b0cb625d 100644 --- a/packages/platform-loader/src/index.js +++ b/packages/platform-loader/src/index.js @@ -37,7 +37,7 @@ function mergeSourceMap(map, inputMap) { // single source file to a single output file. const source = outputMapConsumer.sources[0]; - inputMapConsumer.eachMapping(function(mapping) { + inputMapConsumer.eachMapping((mapping) => { const generatedPosition = outputMapConsumer.generatedPositionFor({ line: mapping.generatedLine, column: mapping.generatedColumn, @@ -65,12 +65,12 @@ function mergeSourceMap(map, inputMap) { } } -module.exports = function(inputSource, inputSourceMap) { +module.exports = function (inputSource, inputSourceMap) { this.cacheable(); const callback = this.async(); const loaderOptions = loaderUtils.getOptions(this); - const resourcePath = this.resourcePath; + const { resourcePath } = this; const sourceMapTarget = path.basename(resourcePath); const options = Object.assign({ name: 'universal-env' }, loaderOptions); diff --git a/packages/build-plugin-midway-faas/README.md b/packages/plugin-midway-faas/README.md similarity index 100% rename from packages/build-plugin-midway-faas/README.md rename to packages/plugin-midway-faas/README.md diff --git a/packages/build-plugin-midway-faas/package.json b/packages/plugin-midway-faas/package.json similarity index 94% rename from packages/build-plugin-midway-faas/package.json rename to packages/plugin-midway-faas/package.json index e2952815a..4225459ae 100644 --- a/packages/build-plugin-midway-faas/package.json +++ b/packages/plugin-midway-faas/package.json @@ -2,7 +2,7 @@ "name": "build-plugin-midway-faas", "version": "1.0.0", "description": "", - "main": "src/index.js", + "main": "lib/index.js", "author": "", "license": "ISC", "dependencies": { diff --git a/packages/build-plugin-midway-faas/src/index.js b/packages/plugin-midway-faas/src/index.js similarity index 87% rename from packages/build-plugin-midway-faas/src/index.js rename to packages/plugin-midway-faas/src/index.js index 2b4f9aa3e..4fffd59ca 100644 --- a/packages/build-plugin-midway-faas/src/index.js +++ b/packages/plugin-midway-faas/src/index.js @@ -2,9 +2,9 @@ const path = require('path'); const fse = require('fs-extra'); const { useExpressDevPack } = require('@midwayjs/faas-dev-pack'); -module.exports = async({ +module.exports = async ({ context, - onGetWebpackConfig + onGetWebpackConfig, }) => { const { rootDir, command } = context; @@ -27,10 +27,11 @@ module.exports = async({ } app.use( + // eslint-disable-next-line react-hooks/rules-of-hooks useExpressDevPack({ functionDir: rootDir, sourceDir: 'src/apis', - }) + }), ); }, }, diff --git a/packages/build-plugin-rax-api-builder/README.md b/packages/plugin-rax-api-builder/README.md similarity index 100% rename from packages/build-plugin-rax-api-builder/README.md rename to packages/plugin-rax-api-builder/README.md diff --git a/packages/build-plugin-rax-api-builder/package.json b/packages/plugin-rax-api-builder/package.json similarity index 97% rename from packages/build-plugin-rax-api-builder/package.json rename to packages/plugin-rax-api-builder/package.json index 5b6ad55dc..075052fcf 100644 --- a/packages/build-plugin-rax-api-builder/package.json +++ b/packages/plugin-rax-api-builder/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "description": "rax app base plugins", "license": "BSD-3-Clause", - "main": "src/index.js", + "main": "lib/index.js", "repository": { "type": "git", "url": "git+https://github.com/raxjs/rax-scripts.git" diff --git a/packages/build-plugin-rax-api-builder/src/build.js b/packages/plugin-rax-api-builder/src/build.js similarity index 95% rename from packages/build-plugin-rax-api-builder/src/build.js rename to packages/plugin-rax-api-builder/src/build.js index 4381f0599..068d56018 100644 --- a/packages/build-plugin-rax-api-builder/src/build.js +++ b/packages/plugin-rax-api-builder/src/build.js @@ -3,7 +3,7 @@ const resolve = require('rollup-plugin-node-resolve'); const commonjs = require('rollup-plugin-commonjs'); const typescript = require('rollup-plugin-typescript'); const babel = require('rollup-plugin-babel'); -const uglify = require('rollup-plugin-uglify').uglify; +const { uglify } = require('rollup-plugin-uglify'); const replace = require('rollup-plugin-replace'); const gzipSize = require('gzip-size'); const path = require('path'); @@ -15,10 +15,10 @@ function getExtension(format) { return ext; default: return ext; - }; + } } -async function build({ rootDir, entry = 'src/index.ts', shouldMinify = false, format = 'cjs', outDir = 'lib'}) { +async function build({ rootDir, entry = 'src/index.ts', shouldMinify = false, format = 'cjs', outDir = 'lib' }) { const output = { }; const input = entry; diff --git a/packages/build-plugin-rax-api-builder/src/index.js b/packages/plugin-rax-api-builder/src/index.js similarity index 100% rename from packages/build-plugin-rax-api-builder/src/index.js rename to packages/plugin-rax-api-builder/src/index.js diff --git a/packages/plugin-rax-app/README.md b/packages/plugin-rax-app/README.md new file mode 100644 index 000000000..63690f366 --- /dev/null +++ b/packages/plugin-rax-app/README.md @@ -0,0 +1,38 @@ +# plugin-rax-app + +> The basic webpack configuration for rax project + +## Usage + +### registerUserConfig + +`build.json` + +```json +{ + "entry": "", + "alias": {}, + "publicPath": "", + //... +} +``` + +### registerCliOption + +```bash +--port +--https +# ... +``` + +### webpack config + +- TypeScript +- css/sass/less/CSS Modules +- mock +- proxy +- public/ + +## License + +MIT diff --git a/packages/plugin-rax-app/package.json b/packages/plugin-rax-app/package.json new file mode 100644 index 000000000..0f31c3a9a --- /dev/null +++ b/packages/plugin-rax-app/package.json @@ -0,0 +1,45 @@ +{ + "name": "build-plugin-rax-app", + "version": "6.0.1", + "description": "The basic webpack configuration for rax project", + "author": "Rax Team", + "main": "lib/index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "plugin", + "rax" + ], + "license": "MIT", + "dependencies": { + "rax-webpack-config": "^1.0.0", + "rax-babel-config": "^1.0.1", + "rax-jest-config": "^1.0.0", + "rax-platform-loader": "^1.0.0", + "@builder/user-config": "^0.1.0", + "@builder/app-helpers": "^1.0.0", + "chalk": "^4.0.0", + "debug": "^4.1.1", + "fs-extra": "^8.1.0", + "lodash": "^4.17.15", + "mkcert": "^1.2.0", + "path-exists": "^4.0.0", + "react-dev-utils": "^10.2.1", + "webpackbar": "^4.0.0", + "qrcode-terminal": "^0.12.0", + "mini-css-extract-plugin": "^1.2.1", + "copy-webpack-plugin": "^5.0.4", + "postcss-import": "^12.0.1", + "postcss-preset-env": "^6.7.0", + "null-loader": "^4.0.1" + }, + "devDependencies": { + "webpack": "^4.41.1" + }, + "repository": { + "type": "git", + "url": "git@github.com:alibaba/ice.git" + }, + "gitHead": "07ac7bb07162aac8c90778dd1de4a2060f8df498" +} diff --git a/packages/plugin-rax-app/src/base.js b/packages/plugin-rax-app/src/base.js new file mode 100644 index 000000000..8a2e3c494 --- /dev/null +++ b/packages/plugin-rax-app/src/base.js @@ -0,0 +1,81 @@ +const { getEnhancedWebpackConfig } = require('@builder/user-config'); +const getWebpackConfig = require('rax-webpack-config'); +const getBabelConfig = require('rax-babel-config'); +const ProgressPlugin = require('webpackbar'); +const path = require('path'); +const CopyWebpackPlugin = require('copy-webpack-plugin'); +const fs = require('fs-extra'); + +module.exports = (api, { target, babelConfigOptions, progressOptions = {} }) => { + const { context, onGetWebpackConfig } = api; + const { rootDir, command, userConfig } = context; + + const mode = command === 'start' ? 'development' : 'production'; + const babelConfig = getBabelConfig(babelConfigOptions); + const webpackConfig = getWebpackConfig({ + rootDir, + mode, + babelConfig, + target, + }); + const enhancedWebpackConfig = getEnhancedWebpackConfig(api, { + target, + webpackConfig, + babelConfig, + }); + + enhancedWebpackConfig + .plugin('ProgressPlugin') + .use(ProgressPlugin, [ + Object.assign({ color: '#F4AF3D' }, progressOptions), + ]); + + // Copy public dir + if (fs.existsSync(path.resolve(rootDir, 'public'))) { + enhancedWebpackConfig.plugin('CopyWebpackPlugin').use(CopyWebpackPlugin, [[]]); + } + + ['jsx', 'tsx'].forEach((ruleName) => { + enhancedWebpackConfig.module + .rule(ruleName) + .use('platform-loader') + .loader(require.resolve('rax-platform-loader')) + .options({ + platform: target, + }); + }); + + onGetWebpackConfig(target, (config) => { + // Set public url after developer has set public path + // Get public path + let publicUrl = config.output.get('publicPath'); + + // Developer will use process.env.PUBLIC_URL + '/logo.png', so it need remove last / + if (publicUrl && publicUrl.endsWith('/')) { + publicUrl = publicUrl.substring(0, publicUrl.length - 1); + } + + config.plugin('DefinePlugin').tap((args) => [ + Object.assign(...args, { + 'process.env.PUBLIC_URL': JSON.stringify(publicUrl), + }), + ]); + + const { outputDir = 'build' } = userConfig; + // Copy public dir + if (config.plugins.has('CopyWebpackPlugin')) { + config.plugin('CopyWebpackPlugin').tap(([copyList]) => { + return [ + copyList.concat([ + { + from: path.resolve(rootDir, 'public'), + to: path.resolve(rootDir, outputDir, target), + }, + ]), + ]; + }); + } + }); + + return enhancedWebpackConfig; +}; diff --git a/packages/plugin-rax-app/src/config.js b/packages/plugin-rax-app/src/config.js new file mode 100644 index 000000000..4fec3b5ba --- /dev/null +++ b/packages/plugin-rax-app/src/config.js @@ -0,0 +1,52 @@ +/* eslint global-require: 0 */ +module.exports = [ + { + name: 'devServer', + defaultValue: { + disableHostCheck: true, + compress: true, + // Use 'ws' instead of 'sockjs-node' on server since webpackHotDevClient is using native websocket + transportMode: 'ws', + logLevel: 'silent', + clientLogLevel: 'none', + hot: true, + publicPath: '/', + quiet: false, + watchOptions: { + ignored: /node_modules/, + aggregateTimeout: 600, + }, + before(app) { + app.use((req, res, next) => { + // set cros for all served files + res.set('Access-Control-Allow-Origin', '*'); + next(); + }); + }, + // For mutilple task, web will occupy the server root route + writeToDisk: true, + historyApiFallback: true, + }, + }, + { + name: 'outputAssetsPath', + defaultValue: { + js: '', + css: '', + }, + }, + { + name: 'inlineStyle', + defaultValue: false, + configWebpack: require('./userConfig/inlineStyle'), + validation: 'boolean', + }, + { + name: 'polyfill', + defaultValue: false, + }, + { + name: 'compileDependencies', + defaultValue: [''], + }, +]; diff --git a/packages/build-plugin-rax-app/src/constants.js b/packages/plugin-rax-app/src/constants.js similarity index 76% rename from packages/build-plugin-rax-app/src/constants.js rename to packages/plugin-rax-app/src/constants.js index 50ad1e15d..41d3c78bb 100644 --- a/packages/build-plugin-rax-app/src/constants.js +++ b/packages/plugin-rax-app/src/constants.js @@ -1,10 +1,12 @@ module.exports = { WEB: 'web', DOCUMENT: 'document', + SSR: 'ssr', WEEX: 'weex', KRAKEN: 'kraken', MINIAPP: 'miniapp', WECHAT_MINIPROGRAM: 'wechat-miniprogram', BYTEDANCE_MICROAPP: 'bytedance-microapp', QUICKAPP: 'quickapp', + GET_RAX_APP_WEBPACK_CONFIG: 'getRaxAppWebpackConfig', }; diff --git a/packages/plugin-rax-app/src/index.js b/packages/plugin-rax-app/src/index.js new file mode 100644 index 000000000..38d129079 --- /dev/null +++ b/packages/plugin-rax-app/src/index.js @@ -0,0 +1,39 @@ +const path = require('path'); +const { applyCliOption, applyUserConfig } = require('@builder/user-config'); +const getBase = require('./base'); +const { GET_RAX_APP_WEBPACK_CONFIG } = require('./constants'); +const setTest = require('./setTest'); +const setDev = require('./setDev'); +const setBuild = require('./setBuild'); +const customConfigs = require('./config'); + +module.exports = (api) => { + const { onGetWebpackConfig, context, setValue } = api; + const { command, rootDir } = context; + setValue(GET_RAX_APP_WEBPACK_CONFIG, getBase); + + // register cli option + applyCliOption(api); + + // register user config + applyUserConfig(api, { customConfigs }); + + // set webpack config + onGetWebpackConfig((chainConfig) => { + // add resolve modules of project node_modules + chainConfig.resolve.modules.add(path.join(rootDir, 'node_modules')); + }); + + if (command === 'start') { + setDev(api); + } + + if (command === 'build') { + setBuild(api); + } + + if (command === 'test') { + setTest(api); + } +}; + diff --git a/packages/build-plugin-rax-app/src/config/postcss.config.js b/packages/plugin-rax-app/src/postcss.config.js similarity index 61% rename from packages/build-plugin-rax-app/src/config/postcss.config.js rename to packages/plugin-rax-app/src/postcss.config.js index ba8cd2878..18fd1e03a 100644 --- a/packages/build-plugin-rax-app/src/config/postcss.config.js +++ b/packages/plugin-rax-app/src/postcss.config.js @@ -1,7 +1,9 @@ +/* eslint-disable no-case-declarations */ +/* eslint-disable global-require */ const atImport = require('postcss-import'); // See https://github.com/postcss/postcss-loader#context-ctx -module.exports = ({ file, options, env }) => { +module.exports = ({ options }) => { const type = options && options.type; return { plugins: getPlugins(type), @@ -10,30 +12,31 @@ module.exports = ({ file, options, env }) => { function getPlugins(type) { switch (type) { + case 'normal': + return [ + atImport(), + ]; // Inline style - case 'inline': + case 'web-inline': return [ require('postcss-plugin-rpx2vw')(), - atImport() + atImport(), ]; // extract css file in web while inlineStyle is disabled - // web/miniapp standard + // web standard case 'web': - case 'miniapp': - const plugins = [ + return [ require('postcss-preset-env')({ autoprefixer: { flexbox: 'no-2009', }, stage: 3, }), - atImport() + require('postcss-plugin-rpx2vw')(), + atImport(), ]; - if (type === 'web') { - plugins.push(require('postcss-plugin-rpx2vw')()); - } - return plugins; + default: + return []; } - return []; } diff --git a/packages/plugin-rax-app/src/setBuild.js b/packages/plugin-rax-app/src/setBuild.js new file mode 100644 index 000000000..fefb05415 --- /dev/null +++ b/packages/plugin-rax-app/src/setBuild.js @@ -0,0 +1,96 @@ +const path = require('path'); +const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages'); +const chalk = require('chalk'); +const { + MINIAPP, + WEB, + WECHAT_MINIPROGRAM, + BYTEDANCE_MICROAPP, + WEEX, + KRAKEN, +} = require('./constants'); + +const highlightPrint = chalk.hex('#F4AF3D'); +const { logWebpackConfig } = require('./utils'); + +module.exports = (api) => { + const { context, onHook } = api; + const { rootDir, userConfig } = context; + + onHook('before.build.run', ({ config: configs }) => { + logWebpackConfig(configs); + }); + + onHook('after.build.compile', ({ stats }) => { + const statsJson = stats.toJson({ + all: false, + errors: true, + warnings: true, + timings: true, + }); + const messages = formatWebpackMessages(statsJson); + // Do not print localUrl and assets information when containing an error + const isSuccessful = !messages.errors.length; + const { outputDir = 'build', targets } = userConfig; + + if (isSuccessful) { + console.log(highlightPrint('Build finished:')); + console.log(); + + if (targets.includes(WEB)) { + console.log(highlightPrint('[Web] Bundle at:')); + console.log( + ' ', + chalk.underline.white(path.resolve(rootDir, outputDir, WEB)), + ); + console.log(); + } + + if (targets.includes(WEEX)) { + console.log(highlightPrint('[Weex] Bundle at:')); + console.log( + ' ', + chalk.underline.white(path.resolve(rootDir, outputDir, WEEX)), + ); + console.log(); + } + + if (targets.includes(KRAKEN)) { + console.log(highlightPrint('[Kraken] Bundle at:')); + console.log( + ' ', + chalk.underline.white(path.resolve(rootDir, outputDir, KRAKEN)), + ); + console.log(); + } + + if (targets.includes(MINIAPP)) { + console.log(highlightPrint('[Alibaba MiniApp] Bundle at:')); + console.log( + ' ', + chalk.underline.white(path.resolve(rootDir, outputDir, MINIAPP)), + ); + console.log(); + } + + if (targets.includes(WECHAT_MINIPROGRAM)) { + console.log(highlightPrint('[WeChat MiniProgram] Bundle at:')); + console.log( + ' ', + chalk.underline.white(path.resolve(rootDir, outputDir, WECHAT_MINIPROGRAM)), + ); + console.log(); + } + + if (targets.includes(BYTEDANCE_MICROAPP)) { + console.log(highlightPrint('[ByteDance MicroApp] Bundle at:')); + console.log( + ' ', + chalk.underline.white(path.resolve(rootDir, outputDir, BYTEDANCE_MICROAPP)), + ); + console.log(); + } + } + }); +}; + diff --git a/packages/plugin-rax-app/src/setDev.js b/packages/plugin-rax-app/src/setDev.js new file mode 100644 index 000000000..7b63b2c56 --- /dev/null +++ b/packages/plugin-rax-app/src/setDev.js @@ -0,0 +1,184 @@ +const chalk = require('chalk'); +const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages'); +const openBrowser = require('react-dev-utils/openBrowser'); +const qrcode = require('qrcode-terminal'); +const path = require('path'); +const fs = require('fs-extra'); + +const logWebpackConfig = require('./utils/logWebpackConfig'); +const { + MINIAPP, + WEB, + WECHAT_MINIPROGRAM, + BYTEDANCE_MICROAPP, + WEEX, + KRAKEN, +} = require('./constants'); + +const highlightPrint = chalk.hex('#F4AF3D'); + +module.exports = function (api) { + // eslint-disable-next-line global-require + const { context, onHook } = api; + const { commandArgs, userConfig, rootDir } = context; + const { targets } = userConfig; + let webEntryKeys = []; + let weexEntryKeys = []; + let krakenEntryKeys = []; + let webMpa = false; + let weexMpa = false; + let krakenMpa = false; + let isFirstCompile = true; + const getWebpackEntry = (configs, configName) => { + const taskConfig = configs.find((webpackConfig) => webpackConfig.name === configName); + if (!taskConfig || !taskConfig.entry) { + return {}; + } + return taskConfig.entry; + }; + onHook('before.start.run', ({ config: configs }) => { + webEntryKeys = Object.keys(getWebpackEntry(configs, 'web')); + weexEntryKeys = Object.keys(getWebpackEntry(configs, 'weex')); + krakenEntryKeys = Object.keys(getWebpackEntry(configs, 'kraken')); + webMpa = userConfig.web && userConfig.web.mpa; + weexMpa = userConfig.weex && userConfig.weex.mpa; + krakenMpa = userConfig.kraken && userConfig.kraken.mpa; + + // Remove outputDir when start devServer + const { outputDir = 'build' } = userConfig; + configs.forEach((config) => { + fs.removeSync(path.resolve(rootDir, outputDir, config.name)); + }); + + logWebpackConfig(configs); + }); + + onHook('after.start.compile', async ({ urls, stats }) => { + const statsJson = stats.toJson({ + all: false, + errors: true, + warnings: true, + timings: true, + }); + const messages = formatWebpackMessages(statsJson); + // Do not print localUrl and assets information when containing an error + const isSuccessful = !messages.errors.length; + const { outputDir = 'build' } = userConfig; + + if (isSuccessful) { + if (commandArgs.disableAssets === false) { + console.log( + // eslint-disable-next-line @iceworks/best-practices/recommend-polyfill + stats.toString({ + errors: false, + warnings: false, + colors: true, + assets: true, + chunks: false, + entrypoints: false, + modules: false, + timings: false, + }), + ); + } + + if (targets.includes(MINIAPP)) { + console.log( + highlightPrint( + ' [Alibaba Miniapp] Use ali miniapp developer tools to open the following folder:', + ), + ); + console.log( + ' ', + chalk.underline.white(path.resolve(rootDir, outputDir, MINIAPP)), + ); + console.log(); + } + + if (targets.includes(WECHAT_MINIPROGRAM)) { + console.log( + highlightPrint( + ' [WeChat MiniProgram] Use wechat miniprogram developer tools to open the following folder:', + ), + ); + console.log( + ' ', + chalk.underline.white(path.resolve(rootDir, outputDir, WECHAT_MINIPROGRAM)), + ); + console.log(); + } + + if (targets.includes(BYTEDANCE_MICROAPP)) { + console.log( + highlightPrint( + ' [Bytedance Microapp] Use bytedance microapp developer tools to open the following folder:', + ), + ); + console.log( + ' ', + chalk.underline.white(path.resolve(rootDir, outputDir, BYTEDANCE_MICROAPP)), + ); + console.log(); + } + if (targets.includes(WEB)) { + console.log(highlightPrint(' [Web] Development server at: ')); + // do not open browser when restart dev + const shouldOpenBrowser = !commandArgs.disableOpen && !process.env.RESTART_DEV && isFirstCompile; + isFirstCompile = false; + if (webEntryKeys.length > 0) { + let openEntries = []; + if (commandArgs.mpaEntry) { + openEntries = commandArgs.mpaEntry.split(','); + } else { + openEntries.push(webEntryKeys[0]); + } + webEntryKeys.forEach((entryKey) => { + const entryPath = webMpa ? `${entryKey}.html` : ''; + console.log(` ${chalk.underline.white(`${urls.localUrlForBrowser}${entryPath}`)}`); + console.log(` ${chalk.underline.white(`${urls.lanUrlForBrowser}${entryPath}`)}`); + console.log(); + if (shouldOpenBrowser && openEntries.includes(entryKey)) { + openBrowser(`${urls.localUrlForBrowser}${entryPath}`); + } + }); + } else { + console.log(` ${chalk.underline.white(`${urls.localUrlForBrowser}`)}`); + console.log(` ${chalk.underline.white(`${urls.lanUrlForBrowser}`)}`); + console.log(); + + if (shouldOpenBrowser) { + openBrowser(`${urls.localUrlForBrowser}`); + } + } + } + + if (targets.includes(KRAKEN)) { + console.log(highlightPrint(' [Kraken] Development server at: ')); + krakenEntryKeys.forEach((entryKey) => { + const krakenURL = `${urls.lanUrlForBrowser}kraken/${krakenMpa ? entryKey : 'index'}.js`; + console.log(` ${chalk.underline.white(krakenURL)}`); + console.log(); + }); + + console.log(highlightPrint(' [Kraken] Run Kraken Playground App: ')); + krakenEntryKeys.forEach((entryKey) => { + const krakenURL = `${urls.lanUrlForBrowser}kraken/${krakenMpa ? entryKey : 'index'}.js`; + console.log(` ${chalk.underline.white(`kraken -u ${krakenURL}`)}`); + console.log(); + }); + } + + if (targets.includes(WEEX)) { + // Use Weex App to scan ip address (mobile phone can't visit localhost). + console.log(highlightPrint(' [Weex] Development server at: ')); + weexEntryKeys.forEach((entryKey) => { + const weexUrl = `${urls.lanUrlForBrowser}weex/${weexMpa ? entryKey : 'index'}.js?wh_weex=true`; + console.log(` ${chalk.underline.white(weexUrl)}`); + console.log(); + qrcode.generate(weexUrl, { small: true }); + console.log(); + }); + } + } + }); +}; diff --git a/packages/plugin-rax-app/src/setTest.js b/packages/plugin-rax-app/src/setTest.js new file mode 100644 index 000000000..b47f84959 --- /dev/null +++ b/packages/plugin-rax-app/src/setTest.js @@ -0,0 +1,33 @@ +const getJestConfig = require('rax-jest-config'); +const logWebpackConfig = require('./utils/logWebpackConfig'); + +module.exports = (api) => { + const { onHook, onGetJestConfig, context } = api; + const { rootDir } = context; + + onHook('before.test.run', ({ config }) => { + logWebpackConfig(config); + }); + + onGetJestConfig((jestConfig) => { + const { moduleNameMapper, ...rest } = jestConfig; + + Object.keys(moduleNameMapper).forEach((key) => { + // escape $ in the beginning. because $ match the end position end in regular expression + // '^$ice/history$' -> '^\$ice/history$' + if (key.indexOf('^$') === 0) { + const newKey = `^\\${key.slice(1)}`; + moduleNameMapper[newKey] = moduleNameMapper[key]; + delete moduleNameMapper[key]; + } + }); + + const defaultJestConfig = getJestConfig({ rootDir, moduleNameMapper }); + return { + ...defaultJestConfig, + ...rest, + // defaultJestConfig.moduleNameMapper already combine jestConfig.moduleNameMapper + moduleNameMapper: defaultJestConfig.moduleNameMapper, + }; + }); +}; diff --git a/packages/plugin-rax-app/src/userConfig/inlineStyle.js b/packages/plugin-rax-app/src/userConfig/inlineStyle.js new file mode 100644 index 000000000..3fe69b14f --- /dev/null +++ b/packages/plugin-rax-app/src/userConfig/inlineStyle.js @@ -0,0 +1,106 @@ +const { resolve } = require('path'); +const MiniCssExtractPlugin = require('mini-css-extract-plugin'); +const { WEB, WEEX, DOCUMENT, SSR, KRAKEN, MINIAPP, WECHAT_MINIPROGRAM } = require('../constants'); + +const configPath = resolve(__dirname, '../'); + +const webStandardList = [ + WEB, +]; + +const inlineStandardList = [ + WEEX, KRAKEN, +]; + +const miniappStandardList = [ + MINIAPP, + WECHAT_MINIPROGRAM, +]; + +module.exports = (config, value, context) => { + const { taskName, command } = context; + const isDev = command === 'start'; + + const cssRule = config.module.rule('css'); + const cssModuleRule = config.module.rule('css-module'); + setCSSRule(cssRule, context, value); + setCSSRule(cssModuleRule, context, value); + + const lessRule = config.module.rule('less'); + const lessModuleRule = config.module.rule('less-module'); + setCSSRule(lessRule, context, value); + setCSSRule(lessModuleRule, context, value); + + const sassRule = config.module.rule('scss'); + const sassModuleRule = config.module.rule('scss-module'); + setCSSRule(sassRule, context, value); + setCSSRule(sassModuleRule, context, value); + if ((webStandardList.includes(taskName) || miniappStandardList.includes(taskName)) && !value) { + config.plugin('MiniCssExtractPlugin') + .use(MiniCssExtractPlugin, [{ + filename: isDev ? `${taskName}/[name].css` : '[name].css', + ignoreOrder: true, + }]); + } +}; + +function setCSSRule(configRule, context, value) { + const { taskName } = context; + const isInlineStandard = inlineStandardList.includes(taskName); + const isWebStandard = webStandardList.includes(taskName); + const isMiniAppStandard = miniappStandardList.includes(taskName); + const isNodeStandard = taskName === DOCUMENT || taskName === SSR; + + // When taskName is weex or kraken, inlineStyle should be true + if (isInlineStandard) { + value = true; + } + + if (value) { + configRule.uses.delete('MiniCssExtractPlugin.loader'); + // enbale inlineStyle + if (isInlineStandard || isMiniAppStandard) { + configInlineStyle(configRule) + .use('postcss-loader') + .tap(getPostCssConfig.bind(null, 'normal')); + } else { + configInlineStyle(configRule) + .use('postcss-loader') + .tap(getPostCssConfig.bind(null, 'web-inline')); + } + } else if (isWebStandard || isMiniAppStandard) { + configRule + .use('postcss-loader') + .tap(getPostCssConfig.bind(null, isWebStandard ? 'web' : 'normal')) + .end(); + } else if (isNodeStandard) { + // Do not generate CSS file, it will be built by web complier + configRule.uses.delete('postcss-loader'); + configRule.uses.delete('MiniCssExtractPlugin.loader'); + configRule + .use('null-loader') + .loader(require.resolve('null-loader')) + .end(); + } +} + +function configInlineStyle(configRule) { + return configRule + .use('css-loader') + .loader(require.resolve('stylesheet-loader')) + .options({ + transformDescendantCombinator: true, + }).end(); +} + +function getPostCssConfig(type, options) { + return { + ...options, + config: { + path: configPath, + ctx: { + type, + }, + }, + }; +} diff --git a/packages/plugin-rax-app/src/utils/index.js b/packages/plugin-rax-app/src/utils/index.js new file mode 100644 index 000000000..2f33c314a --- /dev/null +++ b/packages/plugin-rax-app/src/utils/index.js @@ -0,0 +1,5 @@ +const logWebpackConfig = require('./logWebpackConfig'); + +module.exports = { + logWebpackConfig, +}; diff --git a/packages/plugin-rax-app/src/utils/logWebpackConfig.js b/packages/plugin-rax-app/src/utils/logWebpackConfig.js new file mode 100644 index 000000000..ca5c93397 --- /dev/null +++ b/packages/plugin-rax-app/src/utils/logWebpackConfig.js @@ -0,0 +1,18 @@ +const debug = require('debug')('rax-app'); + +module.exports = (configs) => { + try { + const tmp = []; + debug(JSON.stringify(configs, (key, val) => { + if (val != null && typeof val === 'object') { + if (tmp.indexOf(val) >= 0) { + return; + } + tmp.push(val); + } + return val; + }, 2)); + } catch (error) { + // ignore error + } +}; diff --git a/packages/build-plugin-rax-compat-react/README.md b/packages/plugin-rax-compat-react/README.md similarity index 100% rename from packages/build-plugin-rax-compat-react/README.md rename to packages/plugin-rax-compat-react/README.md diff --git a/packages/build-plugin-rax-compat-react/package.json b/packages/plugin-rax-compat-react/package.json similarity index 86% rename from packages/build-plugin-rax-compat-react/package.json rename to packages/plugin-rax-compat-react/package.json index 275f8b874..abc6d13da 100644 --- a/packages/build-plugin-rax-compat-react/package.json +++ b/packages/plugin-rax-compat-react/package.json @@ -3,5 +3,5 @@ "version": "0.1.1", "description": "A React compatibility plugin for Rax", "license": "BSD-3-Clause", - "main": "src/index.js" + "main": "lib/index.js" } diff --git a/packages/build-plugin-rax-compat-react/src/index.js b/packages/plugin-rax-compat-react/src/index.js similarity index 89% rename from packages/build-plugin-rax-compat-react/src/index.js rename to packages/plugin-rax-compat-react/src/index.js index 194829b1b..be548daaf 100644 --- a/packages/build-plugin-rax-compat-react/src/index.js +++ b/packages/plugin-rax-compat-react/src/index.js @@ -1,6 +1,6 @@ module.exports = ({ onGetWebpackConfig, getValue }) => { const targets = getValue('targets'); - targets.forEach(target => { + targets.forEach((target) => { onGetWebpackConfig(target, (config) => { config.resolve.alias .set('react', 'rax/lib/compat') diff --git a/packages/build-plugin-rax-faas/README.md b/packages/plugin-rax-faas/README.md similarity index 100% rename from packages/build-plugin-rax-faas/README.md rename to packages/plugin-rax-faas/README.md diff --git a/packages/build-plugin-rax-faas/package.json b/packages/plugin-rax-faas/package.json similarity index 92% rename from packages/build-plugin-rax-faas/package.json rename to packages/plugin-rax-faas/package.json index 19fcc8ec7..3fa348d67 100644 --- a/packages/build-plugin-rax-faas/package.json +++ b/packages/plugin-rax-faas/package.json @@ -3,7 +3,7 @@ "version": "0.1.1", "description": "Rax FaaS plugins", "license": "BSD-3-Clause", - "main": "src/index.js", + "main": "lib/index.js", "dependencies": { "fs-extra": "^8.1.0", "js-yaml": "^3.13.1", diff --git a/packages/build-plugin-rax-faas/src/build.js b/packages/plugin-rax-faas/src/build.js similarity index 100% rename from packages/build-plugin-rax-faas/src/build.js rename to packages/plugin-rax-faas/src/build.js diff --git a/packages/build-plugin-rax-faas/src/dev.js b/packages/plugin-rax-faas/src/dev.js similarity index 100% rename from packages/build-plugin-rax-faas/src/dev.js rename to packages/plugin-rax-faas/src/dev.js diff --git a/packages/build-plugin-rax-faas/src/funcBuilder/buildFunctions.js b/packages/plugin-rax-faas/src/funcBuilder/buildFunctions.js similarity index 84% rename from packages/build-plugin-rax-faas/src/funcBuilder/buildFunctions.js rename to packages/plugin-rax-faas/src/funcBuilder/buildFunctions.js index ca165d6de..3a35984d3 100644 --- a/packages/build-plugin-rax-faas/src/funcBuilder/buildFunctions.js +++ b/packages/plugin-rax-faas/src/funcBuilder/buildFunctions.js @@ -4,7 +4,7 @@ const recursiveCopy = require('recursive-copy'); /** * build functions */ -module.exports = async(context, functions) => { +module.exports = async (context, functions) => { const { rootDir, userConfig } = context; const { outputDir } = userConfig; @@ -15,7 +15,9 @@ module.exports = async(context, functions) => { const funcsDir = path.resolve(rootDir, outputDir, 'api', name); // copy function file + // eslint-disable-next-line no-await-in-loop await copy(src, funcsDir); + // eslint-disable-next-line no-await-in-loop await copyDependenices(rootDir, funcsDir, dependencies); } }; @@ -37,6 +39,7 @@ async function copyDependenices(cwd, targetDir, dependencies) { const insPath = dependencies[depKeys[i]]; const cpPath = insPath.replace(cwd, targetDir); + // eslint-disable-next-line no-await-in-loop await copy(insPath, cpPath); } } diff --git a/packages/build-plugin-rax-faas/src/funcBuilder/constants.js b/packages/plugin-rax-faas/src/funcBuilder/constants.js similarity index 100% rename from packages/build-plugin-rax-faas/src/funcBuilder/constants.js rename to packages/plugin-rax-faas/src/funcBuilder/constants.js diff --git a/packages/build-plugin-rax-faas/src/funcBuilder/generateFuncPath.js b/packages/plugin-rax-faas/src/funcBuilder/generateFuncPath.js similarity index 100% rename from packages/build-plugin-rax-faas/src/funcBuilder/generateFuncPath.js rename to packages/plugin-rax-faas/src/funcBuilder/generateFuncPath.js diff --git a/packages/build-plugin-rax-faas/src/funcBuilder/index.js b/packages/plugin-rax-faas/src/funcBuilder/index.js similarity index 100% rename from packages/build-plugin-rax-faas/src/funcBuilder/index.js rename to packages/plugin-rax-faas/src/funcBuilder/index.js diff --git a/packages/build-plugin-rax-faas/src/generateFunctionConfig.js b/packages/plugin-rax-faas/src/generateFunctionConfig.js similarity index 90% rename from packages/build-plugin-rax-faas/src/generateFunctionConfig.js rename to packages/plugin-rax-faas/src/generateFunctionConfig.js index 2f20bae3d..b1ed590d4 100644 --- a/packages/build-plugin-rax-faas/src/generateFunctionConfig.js +++ b/packages/plugin-rax-faas/src/generateFunctionConfig.js @@ -28,6 +28,7 @@ module.exports = (context, options) => { const realRootPath = path.resolve(rootDir, functionGroup.root); const functionArr = []; + // eslint-disable-next-line @iceworks/best-practices/recommend-polyfill for (const [key, value] of Object.entries(functionGroup.functions)) { let customConfig = { name: key, @@ -43,7 +44,7 @@ module.exports = (context, options) => { } const func = Object.assign({}, defaultFncConfig, customConfig); - const [ handlerFile, handlerFunc ] = func.handler.split('.'); + const [handlerFile, handlerFunc] = func.handler.split('.'); func.handlerFile = handlerFile; func.handlerFunc = handlerFunc; func.realPath = path.resolve(realRootPath, func.path); diff --git a/packages/build-plugin-rax-faas/src/generateYaml.js b/packages/plugin-rax-faas/src/generateYaml.js similarity index 100% rename from packages/build-plugin-rax-faas/src/generateYaml.js rename to packages/plugin-rax-faas/src/generateYaml.js diff --git a/packages/build-plugin-rax-faas/src/index.js b/packages/plugin-rax-faas/src/index.js similarity index 100% rename from packages/build-plugin-rax-faas/src/index.js rename to packages/plugin-rax-faas/src/index.js diff --git a/packages/build-plugin-rax-fc/README.md b/packages/plugin-rax-fc/README.md similarity index 100% rename from packages/build-plugin-rax-fc/README.md rename to packages/plugin-rax-fc/README.md diff --git a/packages/build-plugin-rax-fc/package.json b/packages/plugin-rax-fc/package.json similarity index 91% rename from packages/build-plugin-rax-fc/package.json rename to packages/plugin-rax-fc/package.json index fd7ba7c1d..d2422d313 100644 --- a/packages/build-plugin-rax-fc/package.json +++ b/packages/plugin-rax-fc/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "description": "Rax Aliyun Function Compute Plugin", "license": "BSD-3-Clause", - "main": "src/index.js", + "main": "lib/index.js", "dependencies": { "address": "^1.1.2", "fs-extra": "^8.1.0", diff --git a/packages/build-plugin-rax-fc/src/generateYaml.js b/packages/plugin-rax-fc/src/generateYaml.js similarity index 100% rename from packages/build-plugin-rax-fc/src/generateYaml.js rename to packages/plugin-rax-fc/src/generateYaml.js diff --git a/packages/build-plugin-rax-fc/src/index.js b/packages/plugin-rax-fc/src/index.js similarity index 91% rename from packages/build-plugin-rax-fc/src/index.js rename to packages/plugin-rax-fc/src/index.js index 5ce671b35..34bffb32d 100644 --- a/packages/build-plugin-rax-fc/src/index.js +++ b/packages/plugin-rax-fc/src/index.js @@ -1,3 +1,4 @@ +/* eslint-disable */ const fs = require('fs'); const path = require('path'); const shell = require('shelljs'); @@ -12,13 +13,14 @@ module.exports = ({ onGetWebpackConfig, context, onHook }, options = {}) => { const appJSON = require(path.resolve(root, 'src/app.json')); const packageJSON = require(path.resolve(root, 'package.json')); - const routes = appJSON.routes; + const { routes } = appJSON; - const fns = routes.map(route => { + const fns = routes.map((route) => { if (!route.name) { throw new Error(`function name for component '${route.source}' is missing, please config it in 'app.json'`); } + // eslint-disable-next-line no-shadow let path = '.'; // Example: '/about/' -> './about' @@ -30,7 +32,7 @@ module.exports = ({ onGetWebpackConfig, context, onHook }, options = {}) => { name: route.name, handler: 'index.render', methods: ['GET'], - path: path, + path, }; }); @@ -65,7 +67,7 @@ module.exports = ({ onGetWebpackConfig, context, onHook }, options = {}) => { let hasStartFun = false; // start fun after compile to avoid logs be cleared - onHook('after.start.compile', async() => { + onHook('after.start.compile', async () => { if (hasStartFun) { return; } diff --git a/packages/plugin-rax-kraken/package.json b/packages/plugin-rax-kraken/package.json new file mode 100644 index 000000000..5289df935 --- /dev/null +++ b/packages/plugin-rax-kraken/package.json @@ -0,0 +1,25 @@ +{ + "name": "build-plugin-rax-kraken", + "version": "1.0.6", + "description": "rax kraken app plugin", + "main": "lib/index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "plugin", + "rax" + ], + "author": "", + "license": "MIT", + "peerDependencies": { + "@alib/build-scripts": "^0.1.0", + "rax": "^1.0.0" + }, + "dependencies": { + "fs-extra": "^9.0.1", + "webpack-sources": "^2.0.0", + "@builder/mpa-config": "^1.0.0", + "@builder/app-helpers": "^1.0.0" + } +} diff --git a/packages/plugin-rax-kraken/src/constants.js b/packages/plugin-rax-kraken/src/constants.js new file mode 100644 index 000000000..f369bad81 --- /dev/null +++ b/packages/plugin-rax-kraken/src/constants.js @@ -0,0 +1,3 @@ +module.exports = { + GET_RAX_APP_WEBPACK_CONFIG: 'getRaxAppWebpackConfig', +}; diff --git a/packages/plugin-rax-kraken/src/index.js b/packages/plugin-rax-kraken/src/index.js new file mode 100644 index 000000000..7efa19b21 --- /dev/null +++ b/packages/plugin-rax-kraken/src/index.js @@ -0,0 +1,60 @@ +const path = require('path'); +const setMPAConfig = require('@builder/mpa-config'); +const { getMpaEntries } = require('@builder/app-helpers'); +const setEntry = require('./setEntry'); +const { GET_RAX_APP_WEBPACK_CONFIG } = require('./constants'); + +module.exports = (api) => { + const { getValue, context, registerTask, onGetWebpackConfig, registerUserConfig } = api; + + const getWebpackBase = getValue(GET_RAX_APP_WEBPACK_CONFIG); + const target = 'kraken'; + const chainConfig = getWebpackBase(api, { + target, + babelConfigOptions: { styleSheet: true }, + progressOptions: { + name: 'Kraken', + }, + }); + chainConfig.name(target); + chainConfig.taskName = target; + + setEntry(chainConfig, context); + + registerTask(target, chainConfig); + registerUserConfig({ + name: target, + validation: 'object', + }); + + + onGetWebpackConfig(target, (config) => { + const { userConfig, rootDir, command } = context; + const { outputDir = 'build' } = userConfig; + const krakenConfig = userConfig.kraken || {}; + + if (krakenConfig.mpa) { + setMPAConfig.default(config, { context, + type: 'kraken', + entries: getMpaEntries(api, { + target, + appJsonPath: path.join(rootDir, 'src/app.json'), + }) }); + } + + let outputPath; + if (command === 'start') { + // Set output dir + outputPath = path.resolve(rootDir, outputDir); + config.output.filename(`${target}/[name].js`); + config.devServer.contentBase(outputPath); + // Force disable HMR, kraken not support yet. + config.devServer.inline(false); + config.devServer.hot(false); + } else if (command === 'build') { + // Set output dir + outputPath = path.resolve(rootDir, outputDir, target); + } + config.output.path(outputPath); + }); +}; diff --git a/packages/plugin-rax-kraken/src/setEntry.js b/packages/plugin-rax-kraken/src/setEntry.js new file mode 100644 index 000000000..5c03ae4c2 --- /dev/null +++ b/packages/plugin-rax-kraken/src/setEntry.js @@ -0,0 +1,23 @@ +const fs = require('fs-extra'); +const path = require('path'); + +module.exports = (config, context) => { + const { rootDir } = context; + // SPA + const appEntry = moduleResolve(formatPath(path.join(rootDir, './src/app'))); + const entryConfig = config.entry('index'); + + entryConfig.add(appEntry); +}; + +function moduleResolve(filePath) { + const ext = ['.ts', '.js', '.tsx', '.jsx'].find((extension) => fs.existsSync(`${filePath}${extension}`)); + if (!ext) { + throw new Error(`Cannot find target file ${filePath}.`); + } + return require.resolve(`${filePath}${ext}`); +} + +function formatPath(pathStr) { + return process.platform === 'win32' ? pathStr.split(path.sep).join('/') : pathStr; +} diff --git a/packages/plugin-rax-miniapp/package.json b/packages/plugin-rax-miniapp/package.json new file mode 100644 index 000000000..742fcbdc8 --- /dev/null +++ b/packages/plugin-rax-miniapp/package.json @@ -0,0 +1,27 @@ +{ + "name": "build-plugin-rax-miniapp", + "version": "1.1.0", + "description": "rax miniapp app plugin", + "main": "lib/index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "plugin", + "rax" + ], + "author": "", + "license": "MIT", + "peerDependencies": { + "@alib/build-scripts": "^0.1.0", + "rax": "^1.0.0" + }, + "dependencies": { + "fs-extra": "^9.0.1", + "miniapp-runtime-config": "^0.1.3", + "webpack-sources": "^2.0.0", + "miniapp-builder-shared": "^0.1.6", + "copy-webpack-plugin": "^5.0.4", + "miniapp-compile-config": "^0.1.3" + } +} diff --git a/packages/plugin-rax-miniapp/src/constants.js b/packages/plugin-rax-miniapp/src/constants.js new file mode 100644 index 000000000..29878fbf0 --- /dev/null +++ b/packages/plugin-rax-miniapp/src/constants.js @@ -0,0 +1,4 @@ +module.exports = { + GET_RAX_APP_WEBPACK_CONFIG: 'getRaxAppWebpackConfig', + MINIAPP_COMPILED_DIR: 'miniapp-compiled', +}; diff --git a/packages/plugin-rax-miniapp/src/index.js b/packages/plugin-rax-miniapp/src/index.js new file mode 100644 index 000000000..b7826252b --- /dev/null +++ b/packages/plugin-rax-miniapp/src/index.js @@ -0,0 +1,104 @@ +const path = require('path'); +const fs = require('fs-extra'); +const { platformMap } = require('miniapp-builder-shared'); +const { setConfig } = require('miniapp-runtime-config'); +const { setAppConfig: setAppCompileConfig, setComponentConfig: setComponentCompileConfig } = require('miniapp-compile-config'); +const CopyWebpackPlugin = require('copy-webpack-plugin'); +const setEntry = require('./setEntry'); +const { GET_RAX_APP_WEBPACK_CONFIG, MINIAPP_COMPILED_DIR } = require('./constants'); + +module.exports = (api) => { + const { getValue, context, registerTask, onGetWebpackConfig, registerUserConfig } = api; + const { userConfig } = context; + const { targets, inlineStyle } = userConfig; + + const getWebpackBase = getValue(GET_RAX_APP_WEBPACK_CONFIG); + targets.forEach((target) => { + if (['miniapp', 'wechat-miniprogram', 'bytedance-microapp'].includes(target)) { + const chainConfig = getWebpackBase(api, { + target, + babelConfigOptions: { styleSheet: inlineStyle, disableRegenerator: true }, + progressOptions: { + name: platformMap[target].name, + }, + }); + chainConfig.name(target); + chainConfig.taskName = target; + const isCompileProject = userConfig[target] && userConfig[target].buildType === 'compile'; + // Set Entry when it's runtime project + if (!isCompileProject) { + setEntry(chainConfig, context); + } + // Register task + registerTask(target, chainConfig); + registerUserConfig({ + name: target, + validation: 'object', + }); + + onGetWebpackConfig(target, (config) => { + const { rootDir } = context; + const { outputDir = 'build' } = userConfig; + // Set output dir + const outputPath = path.resolve(rootDir, outputDir, target); + config.output.path(outputPath); + + const needCopyDirs = []; + + // Copy src/miniapp-native dir + if (fs.existsSync(path.resolve(rootDir, 'src', 'miniapp-native'))) { + needCopyDirs.push({ + from: path.resolve(rootDir, 'src', 'miniapp-native'), + to: path.resolve(rootDir, outputDir, target, 'miniapp-native'), + }); + } + + // Copy public dir + if (config.plugins.has('CopyWebpackPlugin')) { + config.plugin('CopyWebpackPlugin').tap(([copyList]) => { + return [copyList.concat(needCopyDirs)]; + }); + } else if (needCopyDirs.length > 0) { + config + .plugin('CopyWebpackPlugin') + .use(CopyWebpackPlugin, [needCopyDirs]); + } + + if (isCompileProject) { + setAppCompileConfig(config, userConfig[target] || {}, { target, context, outputPath, entryPath: './src/app' }); + } else { + setConfig(config, userConfig[target] || {}, { + context, + target, + babelRuleName: 'babel-loader', + modernMode: true, + }); + + // If miniapp-compiled dir exists, register a new task + const compiledComponentsPath = path.resolve(rootDir, 'src', MINIAPP_COMPILED_DIR); + if (fs.existsSync(compiledComponentsPath)) { + const compiledComponentsChainConfig = getWebpackBase(api, { + target: 'rax-compiled-components', + babelConfigOptions: { styleSheet: inlineStyle, disableRegenerator: true }, + }); + compiledComponentsChainConfig.plugins.delete('ProgressPlugin'); + compiledComponentsChainConfig.name('rax-compiled-components'); + compiledComponentsChainConfig.taskName = 'rax-compiled-components'; + + setComponentCompileConfig( + compiledComponentsChainConfig, + { disableCopyNpm: true }, + { + target, + context, + outputPath: path.resolve(rootDir, outputDir, target, MINIAPP_COMPILED_DIR), + entryPath: path.join('src', MINIAPP_COMPILED_DIR, 'index'), + }, + ); + registerTask('rax-compiled-components', compiledComponentsChainConfig); + } + } + }); + } + }); +}; diff --git a/packages/plugin-rax-miniapp/src/setEntry.js b/packages/plugin-rax-miniapp/src/setEntry.js new file mode 100644 index 000000000..e805aff5a --- /dev/null +++ b/packages/plugin-rax-miniapp/src/setEntry.js @@ -0,0 +1,24 @@ +const fs = require('fs-extra'); +const path = require('path'); + +module.exports = (config, context) => { + const { rootDir } = context; + + // SPA + const appEntry = moduleResolve(formatPath(path.join(rootDir, './src/app'))); + const entryConfig = config.entry('index'); + + entryConfig.add(appEntry); +}; + +function moduleResolve(filePath) { + const ext = ['.ts', '.js', '.tsx', '.jsx'].find((extension) => fs.existsSync(`${filePath}${extension}`)); + if (!ext) { + throw new Error(`Cannot find target file ${filePath}.`); + } + return require.resolve(`${filePath}${ext}`); +} + +function formatPath(pathStr) { + return process.platform === 'win32' ? pathStr.split(path.sep).join('/') : pathStr; +} diff --git a/packages/build-plugin-rax-now/README.md b/packages/plugin-rax-now/README.md similarity index 100% rename from packages/build-plugin-rax-now/README.md rename to packages/plugin-rax-now/README.md diff --git a/packages/build-plugin-rax-now/package.json b/packages/plugin-rax-now/package.json similarity index 86% rename from packages/build-plugin-rax-now/package.json rename to packages/plugin-rax-now/package.json index 9ea40c40a..d240488a4 100644 --- a/packages/build-plugin-rax-now/package.json +++ b/packages/plugin-rax-now/package.json @@ -3,7 +3,7 @@ "version": "2.0.0", "description": "Rax plugin for deploy app with ZEIT Now", "license": "BSD-3-Clause", - "main": "src/index.js", + "main": "lib/index.js", "dependencies": { } } diff --git a/packages/build-plugin-rax-now/src/index.js b/packages/plugin-rax-now/src/index.js similarity index 90% rename from packages/build-plugin-rax-now/src/index.js rename to packages/plugin-rax-now/src/index.js index 44f1bb822..3600730c8 100644 --- a/packages/build-plugin-rax-now/src/index.js +++ b/packages/plugin-rax-now/src/index.js @@ -9,18 +9,18 @@ module.exports = ({ onGetWebpackConfig, context, onHook }) => { const appJSON = require(path.resolve(root, 'src/app.json')); const packageJSON = require(path.resolve(root, 'package.json')); - const routes = appJSON.routes; + const { routes } = appJSON; const nowJSON = { name: packageJSON.name, builds: [ - {src: '/web/**', use: '@now/static' }, - {src: '/node/**', use: '@now/node' }, + { src: '/web/**', use: '@now/static' }, + { src: '/node/**', use: '@now/node' }, ], routes: [], }; - routes.forEach(route => { + routes.forEach((route) => { let destFile = 'index'; // Example: '/about/' -> 'about/index' diff --git a/packages/build-plugin-rax-pha/README.md b/packages/plugin-rax-pha/README.md similarity index 100% rename from packages/build-plugin-rax-pha/README.md rename to packages/plugin-rax-pha/README.md diff --git a/packages/build-plugin-rax-pha/package.json b/packages/plugin-rax-pha/package.json similarity index 94% rename from packages/build-plugin-rax-pha/package.json rename to packages/plugin-rax-pha/package.json index d4c65c02b..0c08854c0 100755 --- a/packages/build-plugin-rax-pha/package.json +++ b/packages/plugin-rax-pha/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "description": "Rax PHA plugins", "license": "BSD-3-Clause", - "main": "src/index.js", + "main": "lib/index.js", "dependencies": { "@babel/core": "^7.8.6", "fs-extra": "^8.1.0", diff --git a/packages/build-plugin-rax-pha/src/__tests__/manifestHelper.js b/packages/plugin-rax-pha/src/__tests__/manifestHelper.js similarity index 82% rename from packages/build-plugin-rax-pha/src/__tests__/manifestHelper.js rename to packages/plugin-rax-pha/src/__tests__/manifestHelper.js index 836287a8d..04ab63d84 100644 --- a/packages/build-plugin-rax-pha/src/__tests__/manifestHelper.js +++ b/packages/plugin-rax-pha/src/__tests__/manifestHelper.js @@ -1,8 +1,6 @@ -'use strict'; -import manifestHelpers from '../manifestHelpers'; -const { transformAppConfig, getPageManifestByPath } = manifestHelpers; +const { transformAppConfig, getPageManifestByPath } = require('../manifestHelpers') describe('transformAppConfig', () => { it('should transform dataPrefetches', () => { @@ -10,13 +8,13 @@ describe('transformAppConfig', () => { dataPrefetches: [{ url: '/a.com', data: { - id: 123 - } - }] + id: 123, + }, + }], }, true); expect(manifestJSON.data_prefetches.length).toBe(1); expect(manifestJSON.data_prefetches[0].data).toMatchObject({ - id: 123 + id: 123, }); }); @@ -25,8 +23,8 @@ describe('transformAppConfig', () => { window: { title: '', backgroundColor: '', - pullRefresh: true - } + pullRefresh: true, + }, }, true); expect(manifestJSON).toMatchObject({ title: '', background_color: '', pull_refresh: true }); }); @@ -41,9 +39,9 @@ describe('transformAppConfig', () => { path: 'tab1', name: '主会场', icon: '', - activeIcon: '' - }] - } + activeIcon: '', + }], + }, }, true); expect(manifestJSON.tab_bar).toBeTruthy(); @@ -60,16 +58,16 @@ describe('transformAppConfig', () => { dataPrefetches: [{ url: '/a.com', data: { - id: 123 - } - }] + id: 123, + }, + }], }, { path: '/home1', name: 'home1', - source: 'pages/Home1/index' - } - ] + source: 'pages/Home1/index', + }, + ], }, true); expect(manifestJSON.pages.length).toBe(2); expect(manifestJSON.pages[0].data_prefetches).toMatchObject([{ url: '/a.com', data: { id: 123 } }]); @@ -77,7 +75,7 @@ describe('transformAppConfig', () => { it('should not filter whitelist fields', () => { const manifestJSON = transformAppConfig({ - a: 123 + a: 123, }, false); expect(manifestJSON).toMatchObject({ a: 123 }); @@ -94,16 +92,16 @@ describe('getPageManifestByPath', () => { data_prefetches: [{ url: '/a.com', data: { - id: 123 - } - }] + id: 123, + }, + }], }, { path: '/home1', name: 'home1', - source: 'pages/Home1/index' - } - ] + source: 'pages/Home1/index', + }, + ], }; it('should get empty object when no path', () => { @@ -114,36 +112,36 @@ describe('getPageManifestByPath', () => { it('should get first page manifest', () => { const manifest = getPageManifestByPath({ - decamelizeAppConfig: config + decamelizeAppConfig: config, }); expect(manifest).toMatchObject({ path: '/', name: 'home', data_prefetches: [ - { url: '/a.com', data: { id: 123 } } - ] + { url: '/a.com', data: { id: 123 } }, + ], }); }); it('should generate nsr script', () => { const manifest = getPageManifestByPath({ decamelizeAppConfig: config, - nsr: true + nsr: true, }); expect(manifest.nsr_script).toBe('/web/index.nsr.js'); }); it('should delete fields when frame page', () => { - const copyConfig = {...config}; + const copyConfig = { ...config }; copyConfig.pages[0].frame = true; copyConfig.pages[0].tab_bar = { - background_color: '#ff0000' + background_color: '#ff0000', }; const manifest = getPageManifestByPath({ - decamelizeAppConfig: copyConfig + decamelizeAppConfig: copyConfig, }); expect(manifest.pages.length).toBe(2); @@ -154,7 +152,7 @@ describe('getPageManifestByPath', () => { const manifest = getPageManifestByPath({ decamelizeAppConfig: config, path: '/home1', - nsr: true + nsr: true, }); expect(manifest.nsr_script).toBe('/web/home1/index.nsr.js'); diff --git a/packages/build-plugin-rax-pha/src/index.js b/packages/plugin-rax-pha/src/index.js similarity index 98% rename from packages/build-plugin-rax-pha/src/index.js rename to packages/plugin-rax-pha/src/index.js index 746906a42..f30c1300e 100755 --- a/packages/build-plugin-rax-pha/src/index.js +++ b/packages/plugin-rax-pha/src/index.js @@ -31,7 +31,7 @@ module.exports = ({ onGetWebpackConfig, context, registerTask }, option) => { setManifestToDocument({ ...option, context, - config + config, }); }); }; diff --git a/packages/build-plugin-rax-pha/src/manifestHelpers.js b/packages/plugin-rax-pha/src/manifestHelpers.js similarity index 97% rename from packages/build-plugin-rax-pha/src/manifestHelpers.js rename to packages/plugin-rax-pha/src/manifestHelpers.js index ab80782c3..ace08eb82 100644 --- a/packages/build-plugin-rax-pha/src/manifestHelpers.js +++ b/packages/plugin-rax-pha/src/manifestHelpers.js @@ -16,7 +16,7 @@ const retainKeys = [ 'tabHeader', 'tabBar', 'pages', - 'dataPrefetches' + 'dataPrefetches', ]; // transform app config to decamelize @@ -66,7 +66,7 @@ function getPageManifestByPath(options) { manifestData = { ...decamelizeAppConfig, - ...page + ...page, }; // inject nsr_script @@ -87,5 +87,5 @@ function getPageManifestByPath(options) { module.exports = { transformAppConfig, - getPageManifestByPath + getPageManifestByPath, }; diff --git a/packages/build-plugin-rax-pha/src/nsr/entryLoader.js b/packages/plugin-rax-pha/src/nsr/entryLoader.js similarity index 98% rename from packages/build-plugin-rax-pha/src/nsr/entryLoader.js rename to packages/plugin-rax-pha/src/nsr/entryLoader.js index ee0aaa625..5da595dba 100644 --- a/packages/build-plugin-rax-pha/src/nsr/entryLoader.js +++ b/packages/plugin-rax-pha/src/nsr/entryLoader.js @@ -17,7 +17,7 @@ const formatPath = (p) => { return isWin ? p.split(path.sep).join('/') : p; }; -module.exports = function() { +module.exports = function () { const query = typeof this.query === 'string' ? qs.parse(this.query.substr(1)) : this.query; const { absoluteShellPath, diff --git a/packages/build-plugin-rax-pha/src/nsr/getBase.js b/packages/plugin-rax-pha/src/nsr/getBase.js similarity index 97% rename from packages/build-plugin-rax-pha/src/nsr/getBase.js rename to packages/plugin-rax-pha/src/nsr/getBase.js index b1112f339..3273469ce 100644 --- a/packages/build-plugin-rax-pha/src/nsr/getBase.js +++ b/packages/plugin-rax-pha/src/nsr/getBase.js @@ -34,12 +34,12 @@ module.exports = (context) => { const babelConfig = getBabelConfig({ styleSheet: true, jsxToHtml: true, - isNode: true + isNode: true, }); const config = getWebpackBase({ ...context, - babelConfig: babelConfig, + babelConfig, }); const appJSON = require(path.resolve(rootDir, 'src/app.json')); diff --git a/packages/build-plugin-rax-pha/src/nsr/getEntryName.js b/packages/plugin-rax-pha/src/nsr/getEntryName.js similarity index 100% rename from packages/build-plugin-rax-pha/src/nsr/getEntryName.js rename to packages/plugin-rax-pha/src/nsr/getEntryName.js diff --git a/packages/build-plugin-rax-pha/src/plugins/SaveToDesktopPlugin.js b/packages/plugin-rax-pha/src/plugins/SaveToDesktopPlugin.js similarity index 99% rename from packages/build-plugin-rax-pha/src/plugins/SaveToDesktopPlugin.js rename to packages/plugin-rax-pha/src/plugins/SaveToDesktopPlugin.js index 71a4391a3..3f182fcdc 100755 --- a/packages/build-plugin-rax-pha/src/plugins/SaveToDesktopPlugin.js +++ b/packages/plugin-rax-pha/src/plugins/SaveToDesktopPlugin.js @@ -40,7 +40,7 @@ module.exports = class SaveToDesktopPlugin { const manifest = getPageManifestByPath({ ...this.options, decamelizeAppConfig, - publicPath + publicPath, }); if (!manifest) { @@ -81,4 +81,4 @@ module.exports = class SaveToDesktopPlugin { callback(); }); } -}; \ No newline at end of file +}; diff --git a/packages/build-plugin-rax-pha/src/plugins/ServiceWorkerPlugin.js b/packages/plugin-rax-pha/src/plugins/ServiceWorkerPlugin.js similarity index 96% rename from packages/build-plugin-rax-pha/src/plugins/ServiceWorkerPlugin.js rename to packages/plugin-rax-pha/src/plugins/ServiceWorkerPlugin.js index ed626642d..1a193e77a 100755 --- a/packages/build-plugin-rax-pha/src/plugins/ServiceWorkerPlugin.js +++ b/packages/plugin-rax-pha/src/plugins/ServiceWorkerPlugin.js @@ -3,7 +3,7 @@ const { RawSource } = require('webpack-sources'); const SWTemplate = require('../templates/sw'); const SWBSTemplate = require('../templates/swbs'); -const isArray = Array.isArray; +const { isArray } = Array; const PLUGIN_NAME = 'PHA_ServiceWorkerPlugin'; const HTML_PATH = 'web/index.html'; @@ -15,6 +15,7 @@ const DEFAULT_COMBO_PATTERN = ''; // match combo string, like /\\/\\?\\?(.+)/ const DEFAULT_HTML_LOADING_TIMEOUT = 10000; // fetch timeout function patternToString(pattern) { + // eslint-disable-next-line @iceworks/best-practices/recommend-polyfill return pattern.toString(); } diff --git a/packages/build-plugin-rax-pha/src/plugins/SnapshotPlugin.js b/packages/plugin-rax-pha/src/plugins/SnapshotPlugin.js similarity index 99% rename from packages/build-plugin-rax-pha/src/plugins/SnapshotPlugin.js rename to packages/plugin-rax-pha/src/plugins/SnapshotPlugin.js index c4cd4236e..a0d8c50cc 100755 --- a/packages/build-plugin-rax-pha/src/plugins/SnapshotPlugin.js +++ b/packages/plugin-rax-pha/src/plugins/SnapshotPlugin.js @@ -55,4 +55,4 @@ module.exports = class SnapshotPlugin { callback(); }); } -}; \ No newline at end of file +}; diff --git a/packages/build-plugin-rax-pha/src/setManifestToDocument.js b/packages/plugin-rax-pha/src/setManifestToDocument.js similarity index 88% rename from packages/build-plugin-rax-pha/src/setManifestToDocument.js rename to packages/plugin-rax-pha/src/setManifestToDocument.js index 3a72da60f..2bdcff046 100644 --- a/packages/build-plugin-rax-pha/src/setManifestToDocument.js +++ b/packages/plugin-rax-pha/src/setManifestToDocument.js @@ -1,3 +1,4 @@ +/* eslint-disable */ const fs = require('fs-extra'); const path = require('path'); const manifestHelpers = require('./manifestHelpers'); @@ -24,19 +25,19 @@ module.exports = (option) => { ...option, path, publicPath, - decamelizeAppConfig + decamelizeAppConfig, }); manifests.push({ data: pageManifestData, - path + path, }); }); } - config.plugin('document').tap(args => { + config.plugin('document').tap((args) => { return [{ ...args[0], - manifests + manifests, }]; }); -}; \ No newline at end of file +}; diff --git a/packages/build-plugin-rax-pha/src/templates/sw.js b/packages/plugin-rax-pha/src/templates/sw.js similarity index 100% rename from packages/build-plugin-rax-pha/src/templates/sw.js rename to packages/plugin-rax-pha/src/templates/sw.js diff --git a/packages/build-plugin-rax-pha/src/templates/swbs.js b/packages/plugin-rax-pha/src/templates/swbs.js similarity index 100% rename from packages/build-plugin-rax-pha/src/templates/swbs.js rename to packages/plugin-rax-pha/src/templates/swbs.js diff --git a/packages/plugin-rax-web/package.json b/packages/plugin-rax-web/package.json new file mode 100644 index 000000000..29d7a1be0 --- /dev/null +++ b/packages/plugin-rax-web/package.json @@ -0,0 +1,32 @@ +{ + "name": "build-plugin-rax-web", + "version": "1.0.6", + "description": "rax web app plugin", + "main": "lib/index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "plugin", + "rax" + ], + "author": "", + "license": "MIT", + "peerDependencies": { + "@alib/build-scripts": "^0.1.0", + "rax": "^1.0.0" + }, + "dependencies": { + "@builder/mpa-config": "^1.0.0", + "error-stack-tracey": "^0.1.3", + "fs-extra": "^9.0.1", + "klaw-sync": "^6.0.0", + "qs": "^6.9.4", + "rax-server-renderer": "^1.2.0", + "webpack-sources": "^2.0.0", + "webpack": "^4.0.0", + "@builder/app-helpers": "^1.0.0", + "react-dev-utils": "^10.0.0", + "chalk": "^4.1.0" + } +} diff --git a/packages/build-plugin-rax-app/src/plugins/DocumentPlugin/index.js b/packages/plugin-rax-web/src/DocumentPlugin/index.js similarity index 79% rename from packages/build-plugin-rax-app/src/plugins/DocumentPlugin/index.js rename to packages/plugin-rax-web/src/DocumentPlugin/index.js index 45ef6a0d1..78238242a 100644 --- a/packages/build-plugin-rax-app/src/plugins/DocumentPlugin/index.js +++ b/packages/plugin-rax-web/src/DocumentPlugin/index.js @@ -3,11 +3,8 @@ const path = require('path'); const fs = require('fs-extra'); const webpack = require('webpack'); const { RawSource } = require('webpack-sources'); -const { handleWebpackErr } = require('rax-compile-config'); const { parse, print } = require('error-stack-tracey'); -const getBaseConfig = require('./config'); - const PLUGIN_NAME = 'DocumentPlugin'; module.exports = class DocumentPlugin { @@ -29,14 +26,11 @@ module.exports = class DocumentPlugin { } apply(compiler) { - const { context, ...options} = this.options; + const { context, ...options } = this.options; const { rootDir } = context; + const { webpackConfig } = options; const mainConfig = compiler.options; - const baseConfig = getBaseConfig(context, { - alias: mainConfig.resolve ? mainConfig.resolve.alias : {}, - configWebpack: options.configWebpack - }); // Get output dir from filename instead of hard code. const outputFilePrefix = getPathInfoFromFileName(mainConfig.output.filename); @@ -45,21 +39,21 @@ module.exports = class DocumentPlugin { const pages = {}; // Get all entry point names for html file - Object.keys(mainConfig.entry).map(entryName => { + Object.keys(mainConfig.entry).forEach((entryName) => { pages[entryName] = { tempFile: `__${entryName.replace(/\//g, '_')}_document`, - fileName: `${outputFilePrefix}${entryName}.html` + fileName: `${outputFilePrefix}${entryName}.html`, }; }); // Merge the page info from options if (options.pages) { - options.pages.map(page => { + options.pages.forEach((page) => { const pageInfo = pages[page.entryName]; if (pageInfo) { Object.assign(pageInfo, { pagePath: page.path, - source: page.source + source: page.source, }); } }); @@ -71,22 +65,17 @@ module.exports = class DocumentPlugin { // Document path is specified const absoluteDocumentPath = getAbsoluteFilePath(rootDir, 'src/document/index'); - // Shell is enabled by config in app.json, so it can be disabled without delete code - const appConfig = fs.readJsonSync(path.join(rootDir, 'src/app.json')); - const shellPath = appConfig.shell && appConfig.shell.source; - const absoluteShellPath = shellPath ? getAbsoluteFilePath(rootDir, path.join('src', shellPath)) : null; const manifestString = options.manifests ? JSON.stringify(options.manifests) : null; + delete webpackConfig.entry.index; // Add ssr loader for each entry - Object.keys(pages).map((entryName) => { + Object.keys(pages).forEach((entryName) => { const pageInfo = pages[entryName]; const { tempFile, source, pagePath } = pageInfo; const absolutePagePath = options.staticExport && source ? getAbsoluteFilePath(rootDir, path.join('src', source)) : ''; - const query = { absoluteDocumentPath, - absoluteShellPath, absolutePagePath, pagePath, doctype: options.doctype, @@ -96,11 +85,12 @@ module.exports = class DocumentPlugin { query.manifests = manifestString; } - baseConfig.entry(tempFile).add(`${loaderForDocument}?${qs.stringify(query)}!${absoluteDocumentPath}`); + if (!webpackConfig.entry[tempFile]) { + webpackConfig.entry[tempFile] = []; + } + webpackConfig.entry[tempFile].push(`${loaderForDocument}?${qs.stringify(query)}!${absoluteDocumentPath}`); }); - const config = baseConfig.toConfig(); - let cachedHTML = {}; let fileDependencies = []; @@ -114,7 +104,7 @@ module.exports = class DocumentPlugin { compilation.hooks.additionalChunkAssets.tap(PLUGIN_NAME, () => { const childCompilerDependencies = fileDependencies; - childCompilerDependencies.forEach(fileDependency => { + childCompilerDependencies.forEach((fileDependency) => { compilation.compilationDependencies.add(fileDependency); }); }); @@ -129,35 +119,35 @@ module.exports = class DocumentPlugin { * Need to run document compiler as a child compiler, so it can push html file to the web compilation assets. * Because there are other plugins get html file from the compilation of web. */ - const childCompiler = webpack(config); + const childCompiler = webpack(webpackConfig); childCompiler.parentCompilation = mainCompilation; // Run as child to get child compilation childCompiler.runAsChild((err, entries, childCompilation) => { if (err) { - handleWebpackErr(err); + console.log(err); } else { fileDependencies = childCompilation.fileDependencies; } lastHash = currentHash; currentHash = childCompilation.hash; - callback(); }); }); // Render into index.html - compiler.hooks.emit.tapAsync(PLUGIN_NAME, async(compilation, callback) => { + compiler.hooks.emit.tapAsync(PLUGIN_NAME, async (compilation, callback) => { // Render document to html only when hash change to avoid memory leak. if (currentHash !== lastHash) { cachedHTML = await generateHtml(compilation, { pages, - publicPath + publicPath, }); } - for (var page in cachedHTML) { + // eslint-disable-next-line + for (const page in cachedHTML) { compilation.assets[page] = cachedHTML[page]; } @@ -173,13 +163,12 @@ async function generateHtml(compilation, options) { let hasPrintError = false; const htmlMap = {}; - for (var i = 0, l = entries.length; i < l; i++) { + for (let i = 0, l = entries.length; i < l; i++) { const entryName = entries[i]; const { tempFile, fileName } = pages[entryName]; const files = compilation.entrypoints.get(entryName).getFiles(); const assets = getAssetsForPage(files, publicPath); - const documentContent = compilation.assets[`${tempFile}.js`].source(); let pageSource; @@ -188,6 +177,7 @@ async function generateHtml(compilation, options) { const Document = loadDocument(documentContent); pageSource = Document.renderToHTML(assets); } catch (error) { + // eslint-disable-next-line no-await-in-loop const errorStack = await parse(error, documentContent); // Prevent print duplicate error info if (!hasPrintError) { @@ -195,7 +185,7 @@ async function generateHtml(compilation, options) { hasPrintError = true; } - const stackMessage = errorStack.map(frame => { + const stackMessage = errorStack.map((frame) => { if (frame.fromSourceMap) { return `at ${frame.functionName} (${frame.source}:${frame.lineNumber}:${frame.columnNumber})`; } @@ -222,7 +212,7 @@ async function generateHtml(compilation, options) { function getPathInfoFromFileName(fileName) { const paths = fileName.split('/'); paths.pop(); - return paths.length ? paths.join('/') + '/' : ''; + return paths.length ? `${paths.join('/') }/` : ''; } /** @@ -233,7 +223,6 @@ function loadDocument(content) { const tempFn = new Function('require', 'module', content); // eslint-disable-line const tempModule = { exports: {} }; tempFn(require, tempModule); - if (Object.keys(tempModule.exports).length === 0) { throw new Error('Please make sure exports document component!'); } @@ -247,21 +236,20 @@ function loadDocument(content) { * @param {*} publicPath */ function getAssetsForPage(files, publicPath) { - const jsFiles = files.filter(v => /\.js$/i.test(v)); - const cssFiles = files.filter(v => /\.css$/i.test(v)); + const jsFiles = files.filter((v) => /\.js$/i.test(v)); + const cssFiles = files.filter((v) => /\.css$/i.test(v)); return { // Support publicPath use relative path. // Change MPA 'pageName/index.js' to 'index.js', when use relative path. - scripts: jsFiles.map(script => publicPath + (publicPath.startsWith('.') ? path.basename(script) : script)), - styles: cssFiles.map(style => publicPath + (publicPath.startsWith('.') ? path.basename(style) : style)), + scripts: jsFiles.map((script) => publicPath + (publicPath.startsWith('.') ? path.basename(script) : script)), + styles: cssFiles.map((style) => publicPath + (publicPath.startsWith('.') ? path.basename(style) : style)), }; } /** * Get the exact file * @param {*} rootDir '/Document/work/code/rax-demo/' - * @param {*} filePath 'src/shell/index' */ function getAbsoluteFilePath(rootDir, filePath) { const exts = ['.js', '.jsx', '.tsx']; diff --git a/packages/build-plugin-rax-app/src/plugins/DocumentPlugin/loader.js b/packages/plugin-rax-web/src/DocumentPlugin/loader.js similarity index 98% rename from packages/build-plugin-rax-app/src/plugins/DocumentPlugin/loader.js rename to packages/plugin-rax-web/src/DocumentPlugin/loader.js index 7c73f4550..48c5497da 100644 --- a/packages/build-plugin-rax-app/src/plugins/DocumentPlugin/loader.js +++ b/packages/plugin-rax-web/src/DocumentPlugin/loader.js @@ -16,7 +16,7 @@ const formatPath = (p) => { /** * loader for wrap document and pages to be server render function, which can render page to html */ -module.exports = function() { +module.exports = function () { const query = typeof this.query === 'string' ? qs.parse(this.query.substr(1)) : this.query; const { absoluteDocumentPath, @@ -24,7 +24,7 @@ module.exports = function() { absolutePagePath, pagePath, doctype, - manifests + manifests, } = query; const formatedShellPath = absoluteShellPath ? formatPath(absoluteShellPath) : null; diff --git a/packages/plugin-rax-web/src/constants.js b/packages/plugin-rax-web/src/constants.js new file mode 100644 index 000000000..f369bad81 --- /dev/null +++ b/packages/plugin-rax-web/src/constants.js @@ -0,0 +1,3 @@ +module.exports = { + GET_RAX_APP_WEBPACK_CONFIG: 'getRaxAppWebpackConfig', +}; diff --git a/packages/plugin-rax-web/src/index.js b/packages/plugin-rax-web/src/index.js new file mode 100644 index 000000000..db6428730 --- /dev/null +++ b/packages/plugin-rax-web/src/index.js @@ -0,0 +1,82 @@ +const path = require('path'); +const setMPAConfig = require('@builder/mpa-config'); +const { getMpaEntries } = require('@builder/app-helpers'); +const setDev = require('./setDev'); +const setEntry = require('./setEntry'); +const DocumentPlugin = require('./DocumentPlugin'); +const { GET_RAX_APP_WEBPACK_CONFIG } = require('./constants'); + +module.exports = (api) => { + const { onGetWebpackConfig, getValue, context, registerTask, registerUserConfig, registerCliOption } = api; + + const getWebpackBase = getValue(GET_RAX_APP_WEBPACK_CONFIG); + const target = 'web'; + const { userConfig = {} } = context; + const chainConfig = getWebpackBase(api, { + target, + babelConfigOptions: { styleSheet: userConfig.inlineStyle }, + progressOptions: { + name: 'Web', + }, + }); + chainConfig.name(target); + chainConfig.taskName = target; + registerUserConfig({ + name: target, + validation: 'object', + }); + + // Set Entry + setEntry(chainConfig, context); + registerTask(target, chainConfig); + + onGetWebpackConfig(target, (config) => { + const { rootDir, command } = context; + const { outputDir } = userConfig; + const webConfig = userConfig.web || {}; + + // Set output dir + const outputPath = path.resolve(rootDir, outputDir, target); + config.output.path(outputPath); + + if (command === 'start') { + setDev(config); + } + + const webpackConfig = config.toConfig(); + + webpackConfig.target = 'node'; + + webpackConfig.output.libraryTarget = 'commonjs2'; + // do not generate vendor.js when compile document + webpackConfig.optimization.splitChunks.cacheGroups = {}; + + config.plugin('document').use(DocumentPlugin, [ + { + context, + pages: [ + { + entryName: 'index', + path: '/', + }, + ], + doctype: webConfig.doctype, + staticExport: webConfig.staticExport, + webpackConfig, + }, + ]); + if (webConfig.mpa) { + // support --mpa-entry to specify mpa entry + registerCliOption({ + name: 'mpa-entry', + commands: ['start'], + }); + setMPAConfig.default(config, { context, + type: 'web', + entries: getMpaEntries(api, { + target, + appJsonPath: path.join(rootDir, 'src/app.json'), + }) }); + } + }); +}; diff --git a/packages/build-plugin-rax-app/src/config/web/setDev.js b/packages/plugin-rax-web/src/setDev.js similarity index 71% rename from packages/build-plugin-rax-app/src/config/web/setDev.js rename to packages/plugin-rax-web/src/setDev.js index dd7f3b44f..f8205886c 100644 --- a/packages/build-plugin-rax-app/src/config/web/setDev.js +++ b/packages/plugin-rax-web/src/setDev.js @@ -1,16 +1,15 @@ -const path = require('path'); - // The HTML assets path is related to the webpack output filename. // It is determined by webpack configuration, but not vary based on the operating system. -const HTMLAssetPath = 'web/index.html'; +const HTMLAssetPath = 'index.html'; -module.exports = (config, context, index) => { +module.exports = (config) => { config.devServer.set('before', (app, devServer) => { - const compiler = devServer.compiler.compilers[index]; + // Get web compiler for intercept AppHistoryFallback + const compiler = devServer.compiler.compilers[0]; const httpResponseQueue = []; let fallbackHTMLContent; - compiler.hooks.emit.tap('AppHistoryFallback', function(compilation) { + compiler.hooks.emit.tap('AppHistoryFallback', (compilation) => { if (compilation.assets[HTMLAssetPath]) { fallbackHTMLContent = compilation.assets[HTMLAssetPath].source(); } else { @@ -24,7 +23,7 @@ module.exports = (config, context, index) => { } }); - app.get(/^\/?(?!\.(js|html|css|json))$/, function(req, res) { + app.get(/^\/?(?!\.(js|html|css|json))$/, (req, res) => { if (fallbackHTMLContent !== undefined) { res.send(fallbackHTMLContent); } else { diff --git a/packages/plugin-rax-web/src/setEntry.js b/packages/plugin-rax-web/src/setEntry.js new file mode 100644 index 000000000..a12b4cc34 --- /dev/null +++ b/packages/plugin-rax-web/src/setEntry.js @@ -0,0 +1,32 @@ +const path = require('path'); +const fs = require('fs-extra'); + +module.exports = (config, context) => { + const { rootDir, command } = context; + const isDev = command === 'start'; + + // SPA + const appEntry = moduleResolve(formatPath(path.join(rootDir, './src/app'))); + const entryConfig = config.entry('index'); + + config.module.rule('appJSON') + .use('loader'); + + if (isDev) { + entryConfig.add(require.resolve('react-dev-utils/webpackHotDevClient')); + } + entryConfig.add(appEntry); +}; + + +function moduleResolve(filePath) { + const ext = ['.ts', '.js', '.tsx', '.jsx'].find((extension) => fs.existsSync(`${filePath}${extension}`)); + if (!ext) { + throw new Error(`Cannot find target file ${filePath}.`); + } + return require.resolve(`${filePath}${ext}`); +} + +function formatPath(pathStr) { + return process.platform === 'win32' ? pathStr.split(path.sep).join('/') : pathStr; +} diff --git a/packages/plugin-rax-weex/package.json b/packages/plugin-rax-weex/package.json new file mode 100644 index 000000000..5f40d6706 --- /dev/null +++ b/packages/plugin-rax-weex/package.json @@ -0,0 +1,26 @@ +{ + "name": "build-plugin-rax-weex", + "version": "1.0.6", + "description": "rax weex app plugin", + "main": "lib/index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "plugin", + "rax" + ], + "author": "", + "license": "MIT", + "peerDependencies": { + "@alib/build-scripts": "^0.1.0", + "rax": "^1.0.0" + }, + "dependencies": { + "@builder/mpa-config": "^1.0.0", + "fs-extra": "^9.0.1", + "webpack-sources": "^2.0.0", + "@builder/app-helpers": "^1.0.0", + "react-dev-utils": "^10.0.0" + } +} diff --git a/packages/build-plugin-rax-app/src/plugins/WeexFrameworkBannerPlugin.js b/packages/plugin-rax-weex/src/WeexFrameworkBannerPlugin.js similarity index 85% rename from packages/build-plugin-rax-app/src/plugins/WeexFrameworkBannerPlugin.js rename to packages/plugin-rax-weex/src/WeexFrameworkBannerPlugin.js index 2260f4ec7..2e754d3b0 100644 --- a/packages/build-plugin-rax-app/src/plugins/WeexFrameworkBannerPlugin.js +++ b/packages/plugin-rax-weex/src/WeexFrameworkBannerPlugin.js @@ -12,18 +12,19 @@ class WeexFrameworkBannerPlugin { // Webpack 4 if (compiler.hooks && compiler.hooks.compilation && compiler.hooks.compilation.tap) { - compiler.hooks.compilation.tap('WeexFrameworkBannerPlugin', compilation => { + compiler.hooks.compilation.tap('WeexFrameworkBannerPlugin', (compilation) => { // uglify-webpack-plugin will remove javascript's comments in optimizeChunkAssets // need use afterOptimizeChunkAssets to add frameworkComment after that. // like the else block - compilation.hooks.afterOptimizeChunkAssets.tap('WeexFrameworkBannerPlugin', chunks => { + compilation.hooks.afterOptimizeChunkAssets.tap('WeexFrameworkBannerPlugin', (chunks) => { + // eslint-disable-next-line no-restricted-syntax for (const chunk of chunks) { // Entry only if (!chunk.canBeInitial()) { continue; // eslint-disable-line } - chunk.files.forEach(function(file) { + chunk.files.forEach((file) => { compilation.assets[file] = new ConcatSource( frameworkComment, '\n', @@ -37,8 +38,8 @@ class WeexFrameworkBannerPlugin { compiler.plugin('compilation', (compilation) => { // uglify-webpack-plugin will remove javascript's comments in // optimize-chunk-assets, add frameworkComment after that. - compilation.plugin('after-optimize-chunk-assets', function(chunks) { - chunks.forEach(function(chunk) { + compilation.plugin('after-optimize-chunk-assets', (chunks) => { + chunks.forEach((chunk) => { // Entry only try { // In webpack2 chunk.initial was removed. Use isInitial() @@ -47,7 +48,7 @@ class WeexFrameworkBannerPlugin { if (!chunk.isInitial()) return; } - chunk.files.forEach(function(file) { + chunk.files.forEach((file) => { compilation.assets[file] = new ConcatSource( frameworkComment, '\n', diff --git a/packages/plugin-rax-weex/src/constants.js b/packages/plugin-rax-weex/src/constants.js new file mode 100644 index 000000000..f369bad81 --- /dev/null +++ b/packages/plugin-rax-weex/src/constants.js @@ -0,0 +1,3 @@ +module.exports = { + GET_RAX_APP_WEBPACK_CONFIG: 'getRaxAppWebpackConfig', +}; diff --git a/packages/plugin-rax-weex/src/index.js b/packages/plugin-rax-weex/src/index.js new file mode 100644 index 000000000..7b3cfd66d --- /dev/null +++ b/packages/plugin-rax-weex/src/index.js @@ -0,0 +1,59 @@ +const path = require('path'); +const setMPAConfig = require('@builder/mpa-config'); +const { getMpaEntries } = require('@builder/app-helpers'); +const setEntry = require('./setEntry'); +const { GET_RAX_APP_WEBPACK_CONFIG } = require('./constants'); +const WeexFrameworkBannerPlugin = require('./WeexFrameworkBannerPlugin'); + +module.exports = (api) => { + const { getValue, context, registerTask, onGetWebpackConfig, registerUserConfig } = api; + const { userConfig, rootDir, command } = context; + + const getWebpackBase = getValue(GET_RAX_APP_WEBPACK_CONFIG); + const target = 'weex'; + const chainConfig = getWebpackBase(api, { + target: 'weex', + babelConfigOptions: { styleSheet: true }, + progressOptions: { + name: 'Weex', + }, + }); + chainConfig.taskName = target; + + setEntry(chainConfig, context); + + chainConfig.plugin('WeexFrameworkBannerPlugin') + .use(WeexFrameworkBannerPlugin); + chainConfig.name(target); + registerTask(target, chainConfig); + registerUserConfig({ + name: target, + validation: 'object', + }); + + onGetWebpackConfig(target, (config) => { + const { outputDir = 'build', weex = {} } = userConfig; + // set mpa config + if (weex.mpa) { + setMPAConfig.default(config, { context, + type: 'weex', + entries: getMpaEntries(api, { + target, + appJsonPath: path.join(rootDir, 'src/app.json'), + }) }); + } + + let outputPath; + if (command === 'start') { + // Set output dir + outputPath = path.resolve(rootDir, outputDir); + config.devServer.contentBase(outputPath); + config.output.filename(`${target}/[name].js`); + } else if (command === 'build') { + // Set output dir + outputPath = path.resolve(rootDir, outputDir, target); + } + + config.output.path(outputPath); + }); +}; diff --git a/packages/plugin-rax-weex/src/setEntry.js b/packages/plugin-rax-weex/src/setEntry.js new file mode 100644 index 000000000..7f9730fc1 --- /dev/null +++ b/packages/plugin-rax-weex/src/setEntry.js @@ -0,0 +1,28 @@ +const fs = require('fs-extra'); +const path = require('path'); + +module.exports = (config, context) => { + const { rootDir, command } = context; + const isDev = command === 'start'; + + // SPA + const appEntry = moduleResolve(formatPath(path.join(rootDir, './src/app'))); + const entryConfig = config.entry('index'); + + if (isDev) { + entryConfig.add(require.resolve('react-dev-utils/webpackHotDevClient')); + } + entryConfig.add(appEntry); +}; + +function moduleResolve(filePath) { + const ext = ['.ts', '.js', '.tsx', '.jsx'].find((extension) => fs.existsSync(`${filePath}${extension}`)); + if (!ext) { + throw new Error(`Cannot find target file ${filePath}.`); + } + return require.resolve(`${filePath}${ext}`); +} + +function formatPath(pathStr) { + return process.platform === 'win32' ? pathStr.split(path.sep).join('/') : pathStr; +} diff --git a/packages/postcss-plugin-rpx2vw/package.json b/packages/postcss-plugin-rpx2vw/package.json index dc61484ad..35b9b23c7 100644 --- a/packages/postcss-plugin-rpx2vw/package.json +++ b/packages/postcss-plugin-rpx2vw/package.json @@ -2,7 +2,7 @@ "name": "postcss-plugin-rpx2vw", "version": "0.0.2", "description": "Postcss plugin transform rpx to vw or rem.", - "main": "src/index.js", + "main": "lib/index.js", "dependencies": { "postcss": "^7.0.17" } diff --git a/packages/postcss-plugin-rpx2vw/src/__tests__/index.js b/packages/postcss-plugin-rpx2vw/src/__tests__/index.js index fa1081603..6a4d0753d 100644 --- a/packages/postcss-plugin-rpx2vw/src/__tests__/index.js +++ b/packages/postcss-plugin-rpx2vw/src/__tests__/index.js @@ -61,7 +61,7 @@ describe('postcssRpxToVw', () => { const output = '.box { width: 10vw; height: 20vw; }'; const processed = postcss(postcssRpxToVw({ - viewportWidth: 1000 + viewportWidth: 1000, })).process(input).css; expect(processed).toBe(output); }); @@ -71,7 +71,7 @@ describe('postcssRpxToVw', () => { const output = '.box { width: 13.33vw; height: 26.67vw; }'; const processed = postcss(postcssRpxToVw({ - unitPrecision: 2 + unitPrecision: 2, })).process(input).css; expect(processed).toBe(output); }); diff --git a/packages/postcss-plugin-rpx2vw/src/index.js b/packages/postcss-plugin-rpx2vw/src/index.js index 972bbff4c..c31f85e65 100644 --- a/packages/postcss-plugin-rpx2vw/src/index.js +++ b/packages/postcss-plugin-rpx2vw/src/index.js @@ -9,11 +9,11 @@ const defaults = { unitPrecision: 5, }; -module.exports = postcss.plugin('postcss-rpx2vw', function(options) { +module.exports = postcss.plugin('postcss-rpx2vw', (options) => { const opts = Object.assign({}, defaults, options); - return function(root) { - root.walkDecls(function(decl, i) { + return function (root) { + root.walkDecls((decl) => { // This should be the fastest test and will remove most declarations if (decl.value.indexOf('rpx') === -1) return; @@ -21,7 +21,7 @@ module.exports = postcss.plugin('postcss-rpx2vw', function(options) { decl.value = decl.value.replace(rpxRegex, createRpxReplace(opts, unit, opts.viewportWidth)); }); - root.walkAtRules('media', function(rule) { + root.walkAtRules('media', (rule) => { if (rule.params.indexOf('rpx') === -1) return; rule.params = rule.params.replace(rpxRegex, createRpxReplace(opts, opts.viewportUnit, opts.viewportWidth)); @@ -38,7 +38,7 @@ function toFixed(number, precision) { // transform rpx to vw function createRpxReplace(opts, viewportUnit, viewportSize) { - return function(m, $1) { + return function (m, $1) { if (!$1) return m; const pixels = parseFloat($1); const parsedVal = toFixed(pixels / viewportSize * 100, opts.unitPrecision); diff --git a/packages/rax-app-renderer/README.md b/packages/rax-app-renderer/README.md new file mode 100644 index 000000000..d02925739 --- /dev/null +++ b/packages/rax-app-renderer/README.md @@ -0,0 +1 @@ +# `rax-app-renderer` diff --git a/packages/rax-app-renderer/package.json b/packages/rax-app-renderer/package.json new file mode 100644 index 000000000..6b358d99e --- /dev/null +++ b/packages/rax-app-renderer/package.json @@ -0,0 +1,35 @@ +{ + "name": "rax-app-renderer", + "version": "0.1.5", + "description": "", + "author": "ice-admin@alibaba-inc.com", + "homepage": "https://github.com/alibaba/ice#readme", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "driver-universal": "^3.1.0", + "create-app-container": "^0.1.3", + "create-use-router": "^0.1.2", + "universal-env": "^3.0.0" + }, + "devDependencies": { + "rax": "^1.0.0" + }, + "directories": { + "lib": "lib", + "test": "__tests__" + }, + "files": [ + "lib" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/alibaba/ice.git" + }, + "scripts": { + "test": "echo \"Error: run tests from root\" && exit 1" + }, + "bugs": { + "url": "https://github.com/alibaba/ice/issues" + } +} diff --git a/packages/rax-app-renderer/src/index.ts b/packages/rax-app-renderer/src/index.ts new file mode 100644 index 000000000..1c7ffcbc3 --- /dev/null +++ b/packages/rax-app-renderer/src/index.ts @@ -0,0 +1,3 @@ +import raxAppRenderer from './renderer'; + +export default raxAppRenderer; diff --git a/packages/rax-app-renderer/src/renderer.tsx b/packages/rax-app-renderer/src/renderer.tsx new file mode 100644 index 000000000..2d52dfa60 --- /dev/null +++ b/packages/rax-app-renderer/src/renderer.tsx @@ -0,0 +1,174 @@ +/* eslint-disable */ +import { render, createElement, useEffect, useState, Fragment, useLayoutEffect } from 'rax'; +import { createNavigation, createTabBar } from 'create-app-container'; +import { createUseRouter } from 'create-use-router'; +import { isWeb, isWeex, isKraken } from 'universal-env'; +import UniversalDriver from 'driver-universal'; + +const useRouter = createUseRouter({ useState, useLayoutEffect }); + +let AppNavigation; +let TabBar; + +if (isWeb) { + AppNavigation = createNavigation({ createElement, useEffect, useState, Fragment }); +} else { + TabBar = createTabBar({ createElement, useEffect, useState, Fragment }); +} + +let driver = UniversalDriver; + +function _isNullableComponent(component) { + return !component || Array.isArray(component) && component.length === 0; +} + +function _matchInitialComponent(fullpath, routes) { + let initialComponent = null; + for (let i = 0, l = routes.length; i < l; i++) { + if (fullpath === routes[i].path || routes[i].regexp && routes[i].regexp.test(fullpath)) { + initialComponent = routes[i].component; + if (typeof initialComponent === 'function') initialComponent = initialComponent(); + break; + } + } + + return Promise.resolve(initialComponent); +} + +function App(props) { + const { staticConfig, history, routes, InitialComponent, context } = props; + const { component: PageComponent } = useRouter(() => ({ history, routes, InitialComponent })); + + // Return null directly if not matched + if (_isNullableComponent(PageComponent)) return null; + + if (isWeb) { + const navigationProps = Object.assign( + { staticConfig, component: PageComponent, history, location: history.location, routes, InitialComponent }, + { ...context.pageInitialProps }, + ); + return ; + } + + const pageProps = Object.assign({ history, location: history.location, routes, InitialComponent }, { ...context.pageInitialProps }); + + const tabBarProps = { history, config: staticConfig.tabBar }; + return ( + + + + + ); +} + +async function raxAppRenderer(options) { + const { appConfig, setAppConfig } = options || {}; + + setAppConfig(appConfig); + + if (process.env.__IS_SERVER__) return; + + let initialData = {}; + let pageInitialProps = {}; + + // ssr enabled and the server has returned data + if ((window as any).__INITIAL_DATA__) { + initialData = (window as any).__INITIAL_DATA__.initialData; + pageInitialProps = (window as any).__INITIAL_DATA__.pageData; + } else { + // ssr not enabled, or SSR is enabled but the server does not return data + // eslint-disable-next-line + if (appConfig.app && appConfig.app.getInitialData) { + initialData = await appConfig.app.getInitialData(); + } + } + + const context = { initialData, pageInitialProps }; + _renderApp(context, options); +} + +function _renderApp(context, options) { + const { + appConfig, + createBaseApp, + emitLifeCycles, + pathRedirect, + getHistory, + staticConfig, + createAppInstance, + ErrorBoundary, + } = options; + + const { + runtime, + appConfig: appDynamicConfig, + } = createBaseApp(appConfig); + + // Set custom driver + if (typeof staticConfig.driver !== 'undefined') { + driver = staticConfig.driver; + } + + const { routes } = staticConfig; + + // Like https://xxx.com?_path=/page1, use `_path` to jump to a specific route. + const history = getHistory(); + pathRedirect(history, routes); + + let _initialComponent; + return _matchInitialComponent(history.location.pathname, routes) + .then((initialComponent) => { + _initialComponent = initialComponent; + const props = { + staticConfig, + history, + routes, + InitialComponent: _initialComponent, + context, + }; + + const { app = {} } = appDynamicConfig; + const { rootId, ErrorBoundaryFallback, onErrorBoundaryHander, errorBoundary } = app; + + let appInstance; + + // For rax-app 2.x + if (typeof createAppInstance === 'function') { + appInstance = createAppInstance(initialComponent); + } else { + const AppProvider = runtime?.composeAppProvider?.(); + const RootComponent = () => { + if (AppProvider) { + return ( + + ); + } + return ; + }; + const Root = ; + + if (errorBoundary) { + appInstance = ( + {Root} + ); + } else { + appInstance = Root; + } + } + + // Emit app launch cycle + emitLifeCycles(); + + const rootEl = isWeex || isKraken ? null : document.getElementById(rootId); + if (isWeb && rootId === null) console.warn('Error: Can not find #root element, please check which exists in DOM.'); + const isSSR = typeof window !== 'undefined' ? (window as any).__INITIAL_DATA__ && (window as any).__INITIAL_DATA__.__SSR_ENABLED__ : false; + return render( + appInstance, + rootEl, + { driver, hydrate: isSSR }, + ); + }); +} + +export default raxAppRenderer; + diff --git a/packages/rax-app-renderer/tsconfig.json b/packages/rax-app-renderer/tsconfig.json new file mode 100644 index 000000000..a6e51981b --- /dev/null +++ b/packages/rax-app-renderer/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "baseUrl": "./", + "rootDir": "src", + "outDir": "lib", + "jsx": "react", + "jsxFactory": "createElement", + "module": "esNext", + "target": "es5", + "experimentalDecorators": true, + "declaration": true, + "sourceMap": false, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "moduleResolution": "node" + }, +} diff --git a/packages/rax-app/CHANGELOG.md b/packages/rax-app/CHANGELOG.md new file mode 100644 index 000000000..dd11235d8 --- /dev/null +++ b/packages/rax-app/CHANGELOG.md @@ -0,0 +1,32 @@ +## Changelog + +### 3.0.7 (November 12, 2020) + +- Feat: support manually close store.([#3750](https://github.com/alibaba/ice/pull/3750)) +- Feat: support pages that are not in the `src/pages`.([#3750](https://github.com/alibaba/ice/pull/3750)) +- Feat: use `polyfill` field instead of `injectBabel` that can add polyfill by usage.([#3777](https://github.com/alibaba/ice/pull/3777)) +- Feat: add `eslint-reporting-webpack-plugin` for dev mode.([#3771](https://github.com/alibaba/ice/pull/3771)) +- Feat: support use miniapp compile mode in its runtime mode project.([#3766](https://github.com/alibaba/ice/pull/3766)) +- Feat: add rax-platform-loader.([raxjs/rax-scripts#480](https://github.com/raxjs/rax-scripts/pull/480)) +- Fix: `miniapp-native` dir copy logic.([#3761](https://github.com/alibaba/ice/pull/3761)) +- Fix: error when set `ssr: true`.([#3775](https://github.com/alibaba/ice/pull/3775)) +- Chore: remove rax-compile-config.([raxjs/rax-scripts#480](https://github.com/raxjs/rax-scripts/pull/480)) +- Chore: use `react-dev-utils/webpackHotDevClient` instead of `rax-compile-config/hmr`.([#3806](https://github.com/alibaba/ice/pull/3806)) +- Chore: change polyfill load settings.([raxjs/rax-scripts#480](https://github.com/raxjs/rax-scripts/pull/475)) +- Chore: update mini-css-extract-plugin version and set `esModule` to `false` as default.([raxjs/rax-scripts#475](https://github.com/raxjs/rax-scripts/pull/475)) +- Chore: unify the packaging mechanism of icejs and rax-app.([#3753](https://github.com/alibaba/ice/pull/3753)) +- Chore: change `compileDependencies` default value to `['']`.([#3802](https://github.com/alibaba/ice/pull/3802)) +- Enhance: open browser logic, now you can use ` -- --mpa-entry=home` to specify mpa entry.([#3798](https://github.com/alibaba/ice/pull/3798)) +- Docs: update router and change `compileDependencies` related docs.([raxjs/docs#42](https://github.com/raxjs/docs/pull/42) +) + + + +### 3.0.6 (October 30, 2020) + +- Feat: support browser history for web.([#3736](https://github.com/alibaba/ice/pull/3736)) +- Fix: windows path error.([#3695](https://github.com/alibaba/ice/pull/3695)) +- Fix: kraken/weex assets couldn't find.([#3736](https://github.com/alibaba/ice/pull/3736)) +- Enhance: format debug info.([#3736](https://github.com/alibaba/ice/pull/3736)) +- Feat: support miniapp compile config.([#3730](https://github.com/alibaba/ice/pull/3730)) + diff --git a/packages/rax-app/README.md b/packages/rax-app/README.md new file mode 100644 index 000000000..f2b3c2f91 --- /dev/null +++ b/packages/rax-app/README.md @@ -0,0 +1 @@ +# `rax-app` diff --git a/packages/rax-app/bin/child-process-start.js b/packages/rax-app/bin/child-process-start.js new file mode 100644 index 000000000..16435e4fb --- /dev/null +++ b/packages/rax-app/bin/child-process-start.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node +const { childProcessStart } = require('create-cli-utils'); +const getBuiltInPlugins = require('../lib'); + +(async () => { + await childProcessStart(getBuiltInPlugins); +})(); diff --git a/packages/rax-app/bin/rax-cli.js b/packages/rax-app/bin/rax-cli.js new file mode 100755 index 000000000..74aeffbd9 --- /dev/null +++ b/packages/rax-app/bin/rax-cli.js @@ -0,0 +1,10 @@ +#!/usr/bin/env node +const utils = require('create-cli-utils'); +const packageInfo = require('../package.json'); +const getBuiltInPlugins = require('../lib'); + +const forkChildProcessPath = require.resolve('./child-process-start'); + +(async () => { + await utils.createCli(getBuiltInPlugins, forkChildProcessPath, packageInfo); +})(); diff --git a/packages/rax-app/package.json b/packages/rax-app/package.json new file mode 100644 index 000000000..6f2566932 --- /dev/null +++ b/packages/rax-app/package.json @@ -0,0 +1,51 @@ +{ + "name": "rax-app", + "version": "3.0.8", + "description": "command line interface and builtin plugin for rax app", + "author": "ice-admin@alibaba-inc.com", + "homepage": "https://github.com/alibaba/ice#readme", + "license": "MIT", + "main": "lib/index.js", + "bin": { + "rax-app": "./bin/rax-cli.js" + }, + "directories": { + "lib": "lib", + "test": "__tests__" + }, + "dependencies": { + "@alib/build-scripts": "^0.1.24", + "build-plugin-app-core": "0.1.23", + "build-plugin-rax-app": "6.0.0", + "build-plugin-ice-store": "1.7.8", + "build-plugin-rax-web": "1.0.6", + "build-plugin-rax-weex": "1.0.6", + "build-plugin-rax-kraken": "1.0.6", + "build-plugin-rax-miniapp": "1.1.0", + "build-plugin-ssr": "1.0.6", + "chokidar": "^3.3.1", + "commander": "^5.0.0", + "create-cli-utils": "0.1.4", + "detect-port": "^1.3.0", + "inquirer": "^7.1.0", + "yargs-parser": "^18.1.2" + }, + "files": [ + "bin", + "lib" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/alibaba/ice.git" + }, + "scripts": { + "test": "echo \"Error: run tests from root\" && exit 1" + }, + "bugs": { + "url": "https://github.com/alibaba/ice/issues" + }, + "engines": { + "node": ">=10.13.0", + "npm": ">=3.0.0" + } +} diff --git a/packages/rax-app/src/index.ts b/packages/rax-app/src/index.ts new file mode 100644 index 000000000..8f87e3926 --- /dev/null +++ b/packages/rax-app/src/index.ts @@ -0,0 +1,46 @@ +const getBuiltInPlugins = (userConfig) => { + const { targets = ['web'], store = true } = userConfig; + + // built-in plugins for rax app + const builtInPlugins = [ + [ + 'build-plugin-app-core', + { + framework: 'rax', + alias: 'rax-app', + }, + ], + ['build-plugin-rax-app'], + ]; + + if (store) { + builtInPlugins.push(['build-plugin-ice-store']); + } + + if (targets.includes('web')) { + builtInPlugins.push(['build-plugin-rax-web']); + if (userConfig.web && userConfig.web.ssr) { + builtInPlugins.push(['build-plugin-ssr']); + } + } + + if (targets.includes('weex')) { + builtInPlugins.push(['build-plugin-rax-weex']); + } + + if (targets.includes('kraken')) { + builtInPlugins.push(['build-plugin-rax-kraken']); + } + + if ( + targets.includes('miniapp') || + targets.includes('wechat-miniprogram') || + targets.includes('bytedance-microapp') + ) { + builtInPlugins.push(['build-plugin-rax-miniapp']); + } + + return builtInPlugins; +}; + +export = getBuiltInPlugins; diff --git a/packages/rax-app/tsconfig.json b/packages/rax-app/tsconfig.json new file mode 100644 index 000000000..1ba6ca74d --- /dev/null +++ b/packages/rax-app/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.settings.json", + "compilerOptions": { + "baseUrl": "./", + "rootDir": "src", + "outDir": "lib" + }, +} diff --git a/packages/rax-babel-config/package.json b/packages/rax-babel-config/package.json index f6b50e99d..a449b94a9 100644 --- a/packages/rax-babel-config/package.json +++ b/packages/rax-babel-config/package.json @@ -3,7 +3,7 @@ "version": "1.0.1", "description": "rax base babel config", "license": "BSD-3-Clause", - "main": "src/index.js", + "main": "lib/index.js", "repository": { "type": "git", "url": "git+https://github.com/raxjs/rax-scripts.git" diff --git a/packages/rax-babel-config/src/index.js b/packages/rax-babel-config/src/index.js index 45a6ee29a..2e2481eb9 100644 --- a/packages/rax-babel-config/src/index.js +++ b/packages/rax-babel-config/src/index.js @@ -17,7 +17,7 @@ module.exports = (userOptions = {}) => { jsxToHtml, disableRegenerator = false, // preset-env modules options - modules + modules, } = options; const baseConfig = { @@ -31,14 +31,14 @@ module.exports = (userOptions = {}) => { include: [ 'transform-computed-properties', ], - exclude: disableRegenerator ? ['transform-regenerator'] : [] + exclude: disableRegenerator ? ['transform-regenerator'] : [], }, ], [ require.resolve('@babel/preset-react'), { - 'pragma': 'createElement', - 'pragmaFrag': 'Fragment', - 'throwIfNamespace': false, + pragma: 'createElement', + pragmaFrag: 'Fragment', + throwIfNamespace: false, }, ], ], diff --git a/packages/rax-cli/bin/config.js b/packages/rax-cli/bin/config.js index 05575d25c..0f4c7c099 100644 --- a/packages/rax-cli/bin/config.js +++ b/packages/rax-cli/bin/config.js @@ -1,5 +1,5 @@ function getPromptQuestion(appTemplate) { - let promptQuestion = [{ + const promptQuestion = [{ type: 'list', name: 'projectType', message: 'What\'s your project type?', @@ -26,9 +26,9 @@ function getPromptQuestion(appTemplate) { }, { name: 'Plugin (Build plugin for miniapp)', - value: 'plugin' - } - ] + value: 'plugin', + }, + ], }, { type: 'checkbox', name: 'projectTargets', @@ -38,7 +38,7 @@ function getPromptQuestion(appTemplate) { return 'Choose at least one of target.'; }, message: 'Choose targets your project want to run?', - choices: function(answers) { + choices(answers) { let targets = [ { @@ -48,7 +48,7 @@ function getPromptQuestion(appTemplate) { { name: 'WeChat MiniProgram', value: 'wechat-miniprogram', - } + }, ]; if (answers.projectType !== 'plugin') { targets = [{ @@ -106,7 +106,7 @@ function getPromptQuestion(appTemplate) { } function checkTargetExist(allTargets, projectTargets) { - return allTargets.some(target => projectTargets.includes(target)); + return allTargets.some((target) => projectTargets.includes(target)); } module.exports = { diff --git a/packages/rax-cli/bin/rax.js b/packages/rax-cli/bin/rax.js index 9bd386110..d20753d8c 100755 --- a/packages/rax-cli/bin/rax.js +++ b/packages/rax-cli/bin/rax.js @@ -1,5 +1,5 @@ #!/usr/bin/env node - +/* eslint-disable */ const updateNotifier = require('update-notifier'); const fs = require('fs'); const fse = require('fs-extra'); @@ -139,7 +139,7 @@ function askProjectInformaction(appTemplate) { * @return {Boolean} */ const containConflictFile = (targetDir) => { - return conflictFiles.some(filename => fs.existsSync(path.join(targetDir, filename))); + return conflictFiles.some((filename) => fs.existsSync(path.join(targetDir, filename))); }; let prompts = config.getPromptQuestion(appTemplate); @@ -149,7 +149,7 @@ function askProjectInformaction(appTemplate) { type: 'confirm', name: 'shouldInputNewProjectName', message: `The directory ${projectName} contains files that could conflict:\n\n${conflictFiles.join('\n')}\n\nEither try using a new directory name, or still use the directory ${projectName}.`, - default: true + default: true, }, { type: 'input', @@ -169,8 +169,8 @@ function askProjectInformaction(appTemplate) { } projectName = newName; return true; - } - } + }, + }, ].concat(prompts); } @@ -194,7 +194,7 @@ async function createProject(name, verbose, template, userAnswers) { console.log( 'Creating a new Rax project in', - rootDir + rootDir, ); if (projectType === 'app') { @@ -207,8 +207,8 @@ async function createProject(name, verbose, template, userAnswers) { null, { targets: projectTargets, - mpa: appType === 'mpa' - } + mpa: appType === 'mpa', + }, ); } else { const typeToTemplate = { @@ -217,7 +217,7 @@ async function createProject(name, verbose, template, userAnswers) { js: '@icedesign/template-rax', }, api: '@icedesign/template-rax-api', - plugin: '@icedesign/template-rax-miniapp-plugin' + plugin: '@icedesign/template-rax-miniapp-plugin', }; const tempDir = path.join(rootDir, '.tmp'); @@ -231,7 +231,7 @@ async function createProject(name, verbose, template, userAnswers) { npmName: 'rax-example', projectTargets, }, - materialType: 'component' + materialType: 'component', }); await fse.remove(tempDir); } diff --git a/packages/rax-hot-module-replacement-webpack-plugin/README.md b/packages/rax-hot-module-replacement-webpack-plugin/README.md deleted file mode 100644 index e4fe342ec..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/README.md +++ /dev/null @@ -1 +0,0 @@ -# rax-hot-module-replacement-webpack-plugin diff --git a/packages/rax-hot-module-replacement-webpack-plugin/package.json b/packages/rax-hot-module-replacement-webpack-plugin/package.json deleted file mode 100644 index d52844481..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "rax-hot-module-replacement-webpack-plugin", - "version": "0.6.5", - "description": "Rax hot module replacement.", - "main": "./src/HotModuleReplacementPlugin.js", - "repository": { - "type": "git", - "url": "git+https://github.com/raxjs/rax-scripts.git" - }, - "keywords": [ - "Rax", - "hot-loader", - "webpack-plugin" - ], - "bugs": { - "url": "https://github.com/raxjs/rax-scripts/issues" - }, - "homepage": "https://github.com/raxjs/rax-scripts#readme", - "license": "BSD-3-Clause", - "dependencies": { - "tapable": "^0.2.6", - "webpack-sources": "^0.2.3" - } -} diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/BasicEvaluatedExpression.js b/packages/rax-hot-module-replacement-webpack-plugin/src/BasicEvaluatedExpression.js deleted file mode 100644 index c2594c736..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/BasicEvaluatedExpression.js +++ /dev/null @@ -1,179 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ - -'use strict'; - -class BasicEvaluatedExpression { - constructor() { - this.range = null; - } - - isNull() { - return !!this.null; - } - - isString() { - return Object.prototype.hasOwnProperty.call(this, 'string'); - } - - isNumber() { - return Object.prototype.hasOwnProperty.call(this, 'number'); - } - - isBoolean() { - return Object.prototype.hasOwnProperty.call(this, 'bool'); - } - - isRegExp() { - return Object.prototype.hasOwnProperty.call(this, 'regExp'); - } - - isConditional() { - return Object.prototype.hasOwnProperty.call(this, 'options'); - } - - isArray() { - return Object.prototype.hasOwnProperty.call(this, 'items'); - } - - isConstArray() { - return Object.prototype.hasOwnProperty.call(this, 'array'); - } - - isIdentifier() { - return Object.prototype.hasOwnProperty.call(this, 'identifier'); - } - - isWrapped() { - return Object.prototype.hasOwnProperty.call(this, 'prefix') || Object.prototype.hasOwnProperty.call(this, 'postfix'); - } - - isTemplateString() { - return Object.prototype.hasOwnProperty.call(this, 'quasis'); - } - - asBool() { - if (this.isBoolean()) return this.bool; - else if (this.isNull()) return false; - else if (this.isString()) return !!this.string; - else if (this.isNumber()) return !!this.number; - else if (this.isRegExp()) return true; - else if (this.isArray()) return true; - else if (this.isConstArray()) return true; - else if (this.isWrapped()) return this.prefix && this.prefix.asBool() || this.postfix && this.postfix.asBool() ? true : undefined; - else if (this.isTemplateString()) { - if (this.quasis.length === 1) return this.quasis[0].asBool(); - for (let i = 0; i < this.quasis.length; i++) { - if (this.quasis[i].asBool()) return true; - } - // can't tell if string will be empty without executing - } - return undefined; - } - - setString(str) { - if (str === null) - delete this.string; - else - this.string = str; - return this; - } - - setNull() { - this.null = true; - return this; - } - - setNumber(num) { - if (num === null) - delete this.number; - else - this.number = num; - return this; - } - - setBoolean(bool) { - if (bool === null) - delete this.bool; - else - this.bool = bool; - return this; - } - - setRegExp(regExp) { - if (regExp === null) - delete this.regExp; - else - this.regExp = regExp; - return this; - } - - setIdentifier(identifier) { - if (identifier === null) - delete this.identifier; - else - this.identifier = identifier; - return this; - } - - setWrapped(prefix, postfix) { - this.prefix = prefix; - this.postfix = postfix; - return this; - } - - unsetWrapped() { - delete this.prefix; - delete this.postfix; - return this; - } - - setOptions(options) { - if (options === null) - delete this.options; - else - this.options = options; - return this; - } - - setItems(items) { - if (items === null) - delete this.items; - else - this.items = items; - return this; - } - - setArray(array) { - if (array === null) - delete this.array; - else - this.array = array; - return this; - } - - setTemplateString(quasis) { - if (quasis === null) - delete this.quasis; - else - this.quasis = quasis; - return this; - } - - addOptions(options) { - if (!this.options) this.options = []; - options.forEach(item => { - this.options.push(item); - }, this); - return this; - } - - setRange(range) { - this.range = range; - return this; - } -} - -module.exports = BasicEvaluatedExpression; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/Dependency.js b/packages/rax-hot-module-replacement-webpack-plugin/src/Dependency.js deleted file mode 100644 index c8f30b5c9..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/Dependency.js +++ /dev/null @@ -1,54 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; -const compareLocations = require('./compareLocations'); - -class Dependency { - constructor() { - this.module = null; - } - - isEqualResource() { - return false; - } - - // Returns the referenced module and export - getReference() { - if (!this.module) return null; - return { - module: this.module, - importedNames: true, // true: full object, false: only sideeffects/no export, array of strings: the exports with this names - }; - } - - // Returns the exported names - getExports() { - return null; - } - - getWarnings() { - return null; - } - - getErrors() { - return null; - } - - updateHash(hash) { - hash.update((this.module && this.module.id) + ''); - } - - disconnect() { - this.module = null; - } - - // TODO: remove in webpack 3 - compare(a, b) { - return compareLocations(a.loc, b.loc); - } -} -Dependency.compare = (a, b) => compareLocations(a.loc, b.loc); - -module.exports = Dependency; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/HotModuleReplacement.runtime.js b/packages/rax-hot-module-replacement-webpack-plugin/src/HotModuleReplacement.runtime.js deleted file mode 100644 index c2f73c1d3..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/HotModuleReplacement.runtime.js +++ /dev/null @@ -1,584 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -/* global $hash$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk hotDisposeChunk modules */ -module.exports = function() { - var hotApplyOnUpdate = true; - var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars - var hotCurrentModuleData = {}; - var hotCurrentChildModule; // eslint-disable-line no-unused-vars - var hotCurrentParents = []; // eslint-disable-line no-unused-vars - var hotCurrentParentsTemp = []; // eslint-disable-line no-unused-vars - - function hotCreateRequire(moduleId) { // eslint-disable-line no-unused-vars - var me = installedModules[moduleId]; - if (!me) return $require$; - var fn = function(request) { - if (me.hot.active) { - if (installedModules[request]) { - if (installedModules[request].parents.indexOf(moduleId) < 0) - installedModules[request].parents.push(moduleId); - } else { - hotCurrentParents = [moduleId]; - hotCurrentChildModule = request; - } - if (me.children.indexOf(request) < 0) - me.children.push(request); - } else { - console.warn('[HMR] unexpected require(' + request + ') from disposed module ' + moduleId); - hotCurrentParents = []; - } - return $require$(request); - }; - var ObjectFactory = function ObjectFactory(name) { - return { - configurable: true, - enumerable: true, - get: function() { - return $require$[name]; - }, - set: function(value) { - $require$[name] = value; - } - }; - }; - for (var name in $require$) { - if (Object.prototype.hasOwnProperty.call($require$, name) && name !== 'e') { - Object.defineProperty(fn, name, ObjectFactory(name)); // eslint-disable-line - } - } - fn.e = function(chunkId) { - if (hotStatus === 'ready') - hotSetStatus('prepare'); - hotChunksLoading++; - return $require$.e(chunkId).then(finishChunkLoading, function(err) { - finishChunkLoading(); - throw err; - }); - - function finishChunkLoading() { - hotChunksLoading--; - if (hotStatus === 'prepare') { - if (!hotWaitingFilesMap[chunkId]) { - hotEnsureUpdateChunk(chunkId); - } - if (hotChunksLoading === 0 && hotWaitingFiles === 0) { - hotUpdateDownloaded(); - } - } - } - }; - return fn; - } - - function hotCreateModule(moduleId) { // eslint-disable-line no-unused-vars - var hot = { - // private stuff - _acceptedDependencies: {}, - _declinedDependencies: {}, - _selfAccepted: false, - _selfDeclined: false, - _disposeHandlers: [], - _main: hotCurrentChildModule !== moduleId, - - // Module API - active: true, - accept: function(dep, callback) { - if (typeof dep === 'undefined') - hot._selfAccepted = true; - else if (typeof dep === 'function') - hot._selfAccepted = dep; - else if (typeof dep === 'object') - for (var i = 0; i < dep.length; i++) - hot._acceptedDependencies[dep[i]] = callback || function() {}; - else - hot._acceptedDependencies[dep] = callback || function() {}; - }, - decline: function(dep) { - if (typeof dep === 'undefined') - hot._selfDeclined = true; - else if (typeof dep === 'object') - for (var i = 0; i < dep.length; i++) - hot._declinedDependencies[dep[i]] = true; - else - hot._declinedDependencies[dep] = true; - }, - dispose: function(callback) { - hot._disposeHandlers.push(callback); - }, - addDisposeHandler: function(callback) { - hot._disposeHandlers.push(callback); - }, - removeDisposeHandler: function(callback) { - var idx = hot._disposeHandlers.indexOf(callback); - if (idx >= 0) hot._disposeHandlers.splice(idx, 1); - }, - - // Management API - check: hotCheck, - apply: hotApply, - status: function(l) { - if (!l) return hotStatus; - hotStatusHandlers.push(l); - }, - addStatusHandler: function(l) { - hotStatusHandlers.push(l); - }, - removeStatusHandler: function(l) { - var idx = hotStatusHandlers.indexOf(l); - if (idx >= 0) hotStatusHandlers.splice(idx, 1); - }, - - // inherit from previous dispose call - data: hotCurrentModuleData[moduleId] - }; - hotCurrentChildModule = undefined; - return hot; - } - - var hotStatusHandlers = []; - var hotStatus = 'idle'; - - function hotSetStatus(newStatus) { - hotStatus = newStatus; - for (var i = 0; i < hotStatusHandlers.length; i++) - hotStatusHandlers[i].call(null, newStatus); - } - - // while downloading - var hotWaitingFiles = 0; - var hotChunksLoading = 0; - var hotWaitingFilesMap = {}; - var hotRequestedFilesMap = {}; - var hotAvailableFilesMap = {}; - var hotDeferred; - - // The update info - var hotUpdate, hotUpdateNewHash; - - function toModuleId(id) { - var isNumber = +id + '' === id; - return isNumber ? +id : id; - } - - function hotCheck(apply) { - if (hotStatus !== 'idle') throw new Error('check() is only allowed in idle status'); - hotApplyOnUpdate = apply; - hotSetStatus('check'); - return hotDownloadManifest().then(function(update) { - if (!update) { - hotSetStatus('idle'); - return null; - } - hotRequestedFilesMap = {}; - hotWaitingFilesMap = {}; - hotAvailableFilesMap = update.c; - hotUpdateNewHash = update.h; - - hotSetStatus('prepare'); - var promise = new Promise(function(resolve, reject) { - hotDeferred = { - resolve: resolve, - reject: reject - }; - }); - hotUpdate = {}; - /* foreachInstalledChunks */ - { // eslint-disable-line no-lone-blocks - /* globals chunkId */ - hotEnsureUpdateChunk(chunkId); - } - if (hotStatus === 'prepare' && hotChunksLoading === 0 && hotWaitingFiles === 0) { - hotUpdateDownloaded(); - } - return promise; - }); - } - - function hotAddUpdateChunk(chunkId, moreModules) { // eslint-disable-line no-unused-vars - if (!hotAvailableFilesMap[chunkId] || !hotRequestedFilesMap[chunkId]) - return; - hotRequestedFilesMap[chunkId] = false; - for (var moduleId in moreModules) { - if (Object.prototype.hasOwnProperty.call(moreModules, moduleId)) { - hotUpdate[moduleId] = moreModules[moduleId]; - } - } - if (--hotWaitingFiles === 0 && hotChunksLoading === 0) { - hotUpdateDownloaded(); - } - } - - function hotEnsureUpdateChunk(chunkId) { - if (!hotAvailableFilesMap[chunkId]) { - hotWaitingFilesMap[chunkId] = true; - } else { - hotRequestedFilesMap[chunkId] = true; - hotWaitingFiles++; - hotDownloadUpdateChunk(chunkId); - } - } - - function hotUpdateDownloaded() { - hotSetStatus('ready'); - var deferred = hotDeferred; - hotDeferred = null; - if (!deferred) return; - if (hotApplyOnUpdate) { - hotApply(hotApplyOnUpdate).then(function(result) { - deferred.resolve(result); - }, function(err) { - deferred.reject(err); - }); - } else { - var outdatedModules = []; - for (var id in hotUpdate) { - if (Object.prototype.hasOwnProperty.call(hotUpdate, id)) { - outdatedModules.push(toModuleId(id)); - } - } - deferred.resolve(outdatedModules); - } - } - - function hotApply(options) { - if (hotStatus !== 'ready') throw new Error('apply() is only allowed in ready status'); - options = options || {}; - - var cb; - var i; - var j; - var module; - var moduleId; - - function getAffectedStuff(updateModuleId) { - var outdatedModules = [updateModuleId]; - var outdatedDependencies = {}; - - var queue = outdatedModules.slice().map(function(id) { - return { - chain: [id], - id: id - }; - }); - while (queue.length > 0) { - var queueItem = queue.pop(); - var moduleId = queueItem.id; - var chain = queueItem.chain; - module = installedModules[moduleId]; - if (!module || module.hot._selfAccepted) - continue; - if (module.hot._selfDeclined) { - return { - type: 'self-declined', - chain: chain, - moduleId: moduleId - }; - } - if (module.hot._main) { - return { - type: 'unaccepted', - chain: chain, - moduleId: moduleId - }; - } - for (var i = 0; i < module.parents.length; i++) { - var parentId = module.parents[i]; - var parent = installedModules[parentId]; - if (!parent) continue; - if (parent.hot._declinedDependencies[moduleId]) { - return { - type: 'declined', - chain: chain.concat([parentId]), - moduleId: moduleId, - parentId: parentId - }; - } - if (outdatedModules.indexOf(parentId) >= 0) continue; - if (parent.hot._acceptedDependencies[moduleId]) { - if (!outdatedDependencies[parentId]) - outdatedDependencies[parentId] = []; - addAllToSet(outdatedDependencies[parentId], [moduleId]); - continue; - } - delete outdatedDependencies[parentId]; - outdatedModules.push(parentId); - queue.push({ - chain: chain.concat([parentId]), - id: parentId - }); - } - } - - return { - type: 'accepted', - moduleId: updateModuleId, - outdatedModules: outdatedModules, - outdatedDependencies: outdatedDependencies - }; - } - - function addAllToSet(a, b) { - for (var i = 0; i < b.length; i++) { - var item = b[i]; - if (a.indexOf(item) < 0) - a.push(item); - } - } - - // at begin all updates modules are outdated - // the "outdated" status can propagate to parents if they don't accept the children - var outdatedDependencies = {}; - var outdatedModules = []; - var appliedUpdate = {}; - - var warnUnexpectedRequire = function warnUnexpectedRequire() { - console.warn('[HMR] unexpected require(' + result.moduleId + ') to disposed module'); - }; - - for (var id in hotUpdate) { - if (Object.prototype.hasOwnProperty.call(hotUpdate, id)) { - moduleId = toModuleId(id); - var result; - if (hotUpdate[id]) { - result = getAffectedStuff(moduleId); - } else { - result = { - type: 'disposed', - moduleId: id - }; - } - var abortError = false; - var doApply = false; - var doDispose = false; - var chainInfo = ''; - if (result.chain) { - chainInfo = '\nUpdate propagation: ' + result.chain.join(' -> '); - } - switch (result.type) { - case 'self-declined': - if (options.onDeclined) - options.onDeclined(result); - if (!options.ignoreDeclined) - abortError = new Error('Aborted because of self decline: ' + result.moduleId + chainInfo); - break; - case 'declined': - if (options.onDeclined) - options.onDeclined(result); - if (!options.ignoreDeclined) - abortError = new Error('Aborted because of declined dependency: ' + result.moduleId + ' in ' + result.parentId + chainInfo); - break; - case 'unaccepted': - if (options.onUnaccepted) - options.onUnaccepted(result); - if (!options.ignoreUnaccepted) - abortError = new Error('Aborted because ' + moduleId + ' is not accepted' + chainInfo); - break; - case 'accepted': - if (options.onAccepted) - options.onAccepted(result); - doApply = true; - break; - case 'disposed': - if (options.onDisposed) - options.onDisposed(result); - doDispose = true; - break; - default: - throw new Error('Unexception type ' + result.type); - } - if (abortError) { - hotSetStatus('abort'); - return Promise.reject(abortError); - } - if (doApply) { - appliedUpdate[moduleId] = hotUpdate[moduleId]; - addAllToSet(outdatedModules, result.outdatedModules); - for (moduleId in result.outdatedDependencies) { - if (Object.prototype.hasOwnProperty.call(result.outdatedDependencies, moduleId)) { - if (!outdatedDependencies[moduleId]) - outdatedDependencies[moduleId] = []; - addAllToSet(outdatedDependencies[moduleId], result.outdatedDependencies[moduleId]); - } - } - } - if (doDispose) { - addAllToSet(outdatedModules, [result.moduleId]); - appliedUpdate[moduleId] = warnUnexpectedRequire; - } - } - } - - // Store self accepted outdated modules to require them later by the module system - var outdatedSelfAcceptedModules = []; - for (i = 0; i < outdatedModules.length; i++) { - moduleId = outdatedModules[i]; - if (installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted) - outdatedSelfAcceptedModules.push({ - module: moduleId, - errorHandler: installedModules[moduleId].hot._selfAccepted - }); - } - - // Now in "dispose" phase - hotSetStatus('dispose'); - Object.keys(hotAvailableFilesMap).forEach(function(chunkId) { - if (hotAvailableFilesMap[chunkId] === false) { - hotDisposeChunk(chunkId); - } - }); - - var idx; - var queue = outdatedModules.slice(); - while (queue.length > 0) { - moduleId = queue.pop(); - module = installedModules[moduleId]; - if (!module) continue; - - var data = {}; - - // Call dispose handlers - var disposeHandlers = module.hot._disposeHandlers; - for (j = 0; j < disposeHandlers.length; j++) { - cb = disposeHandlers[j]; - cb(data); - } - hotCurrentModuleData[moduleId] = data; - - // disable module (this disables requires from this module) - module.hot.active = false; - - // remove module from cache - delete installedModules[moduleId]; - - // remove "parents" references from all children - for (j = 0; j < module.children.length; j++) { - var child = installedModules[module.children[j]]; - if (!child) continue; - idx = child.parents.indexOf(moduleId); - if (idx >= 0) { - child.parents.splice(idx, 1); - } - } - } - - // remove outdated dependency from module children - var dependency; - var moduleOutdatedDependencies; - for (moduleId in outdatedDependencies) { - if (Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) { - module = installedModules[moduleId]; - if (module) { - moduleOutdatedDependencies = outdatedDependencies[moduleId]; - for (j = 0; j < moduleOutdatedDependencies.length; j++) { - dependency = moduleOutdatedDependencies[j]; - idx = module.children.indexOf(dependency); - if (idx >= 0) module.children.splice(idx, 1); - } - } - } - } - - // Not in "apply" phase - hotSetStatus('apply'); - - hotCurrentHash = hotUpdateNewHash; - - // insert new code - for (moduleId in appliedUpdate) { - if (Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) { - modules[moduleId] = appliedUpdate[moduleId]; - } - } - - // call accept handlers - var error = null; - for (moduleId in outdatedDependencies) { - if (Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) { - module = installedModules[moduleId]; - moduleOutdatedDependencies = outdatedDependencies[moduleId]; - var callbacks = []; - for (i = 0; i < moduleOutdatedDependencies.length; i++) { - dependency = moduleOutdatedDependencies[i]; - cb = module.hot._acceptedDependencies[dependency]; - if (callbacks.indexOf(cb) >= 0) continue; - callbacks.push(cb); - } - for (i = 0; i < callbacks.length; i++) { - cb = callbacks[i]; - try { - cb(moduleOutdatedDependencies); - } catch (err) { - if (options.onErrored) { - options.onErrored({ - type: 'accept-errored', - moduleId: moduleId, - dependencyId: moduleOutdatedDependencies[i], - error: err - }); - } - if (!options.ignoreErrored) { - if (!error) - error = err; - } - } - } - } - } - - // Load self accepted modules - for (i = 0; i < outdatedSelfAcceptedModules.length; i++) { - var item = outdatedSelfAcceptedModules[i]; - moduleId = item.module; - hotCurrentParents = [moduleId]; - try { - $require$(moduleId); - } catch (err) { - if (typeof item.errorHandler === 'function') { - try { - item.errorHandler(err); - } catch (err2) { - if (options.onErrored) { - options.onErrored({ - type: 'self-accept-error-handler-errored', - moduleId: moduleId, - error: err2, - orginalError: err - }); - } - if (!options.ignoreErrored) { - if (!error) - error = err2; - } - if (!error) - error = err; - } - } else { - if (options.onErrored) { - options.onErrored({ - type: 'self-accept-errored', - moduleId: moduleId, - error: err - }); - } - if (!options.ignoreErrored) { - if (!error) - error = err; - } - } - } - } - - // handle errors in accept handlers and self accepted module load - if (error) { - hotSetStatus('fail'); - return Promise.reject(error); - } - - hotSetStatus('idle'); - return new Promise(function(resolve) { - resolve(outdatedModules); - }); - } -}; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/HotModuleReplacementPlugin.js b/packages/rax-hot-module-replacement-webpack-plugin/src/HotModuleReplacementPlugin.js deleted file mode 100644 index 9407854df..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/HotModuleReplacementPlugin.js +++ /dev/null @@ -1,266 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; -var Template = require('./Template'); -var ModuleHotAcceptDependency = require('./dependencies/ModuleHotAcceptDependency'); -var ModuleHotDeclineDependency = require('./dependencies/ModuleHotDeclineDependency'); -var RawSource = require('webpack-sources').RawSource; -var ConstDependency = require('./dependencies/ConstDependency'); -var NullFactory = require('./NullFactory'); -var ParserHelpers = require('./ParserHelpers'); -var RaxJsonpMainTemplatePlugin = require('./RaxJsonpMainTemplatePlugin.js'); - -function HotModuleReplacementPlugin(options) { - options = options || {}; - this.multiStep = options.multiStep; - this.fullBuildTimeout = options.fullBuildTimeout || 200; -} -module.exports = HotModuleReplacementPlugin; - -HotModuleReplacementPlugin.prototype.apply = function(compiler) { - var multiStep = this.multiStep; - var fullBuildTimeout = this.fullBuildTimeout; - var hotUpdateChunkFilename = compiler.options.output.hotUpdateChunkFilename; - var hotUpdateMainFilename = compiler.options.output.hotUpdateMainFilename; - compiler.plugin('compilation', function(compilation, params) { - var hotUpdateChunkTemplate = compilation.hotUpdateChunkTemplate; - if (!hotUpdateChunkTemplate) return; - - var normalModuleFactory = params.normalModuleFactory; - - compilation.dependencyFactories.set(ConstDependency, new NullFactory()); - compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template()); - - compilation.dependencyFactories.set(ModuleHotAcceptDependency, normalModuleFactory); - compilation.dependencyTemplates.set(ModuleHotAcceptDependency, new ModuleHotAcceptDependency.Template()); - - compilation.dependencyFactories.set(ModuleHotDeclineDependency, normalModuleFactory); - compilation.dependencyTemplates.set(ModuleHotDeclineDependency, new ModuleHotDeclineDependency.Template()); - - compilation.plugin('record', function(compilation, records) { - if (records.hash === this.hash) return; - records.hash = compilation.hash; - records.moduleHashs = {}; - this.modules.forEach(function(module) { - var identifier = module.identifier(); - var hash = require('crypto').createHash('md5'); - module.updateHash(hash); - records.moduleHashs[identifier] = hash.digest('hex'); - }); - records.chunkHashs = {}; - this.chunks.forEach(function(chunk) { - records.chunkHashs[chunk.id] = chunk.hash; - }); - records.chunkModuleIds = {}; - this.chunks.forEach(function(chunk) { - records.chunkModuleIds[chunk.id] = chunk.modules.map(function(m) { - return m.id; - }); - }); - }); - var initialPass = false; - var recompilation = false; - compilation.plugin('after-hash', function() { - var records = this.records; - if (!records) { - initialPass = true; - return; - } - if (!records.hash) - initialPass = true; - var preHash = records.preHash || 'x'; - var prepreHash = records.prepreHash || 'x'; - if (preHash === this.hash) { - recompilation = true; - this.modifyHash(prepreHash); - return; - } - records.prepreHash = records.hash || 'x'; - records.preHash = this.hash; - this.modifyHash(records.prepreHash); - }); - compilation.plugin('should-generate-chunk-assets', function() { - if (multiStep && !recompilation && !initialPass) - return false; - }); - compilation.plugin('need-additional-pass', function() { - if (multiStep && !recompilation && !initialPass) - return true; - }); - compiler.plugin('additional-pass', function(callback) { - if (multiStep) - return setTimeout(callback, fullBuildTimeout); - return callback(); - }); - compilation.plugin('additional-chunk-assets', function() { - var records = this.records; - if (records.hash === this.hash) return; - if (!records.moduleHashs || !records.chunkHashs || !records.chunkModuleIds) return; - this.modules.forEach(function(module) { - var identifier = module.identifier(); - var hash = require('crypto').createHash('md5'); - module.updateHash(hash); - hash = hash.digest('hex'); - module.hotUpdate = records.moduleHashs[identifier] !== hash; - }); - var hotUpdateMainContent = { - h: this.hash, - c: {} - }; - Object.keys(records.chunkHashs).forEach(function(chunkId) { - chunkId = isNaN(+chunkId) ? chunkId : +chunkId; - var currentChunk = this.chunks.find(chunk => chunk.id === chunkId); - if (currentChunk) { - var newModules = currentChunk.modules.filter(function(module) { - return module.hotUpdate; - }); - var allModules = {}; - currentChunk.modules.forEach(function(module) { - allModules[module.id] = true; - }); - var removedModules = records.chunkModuleIds[chunkId].filter(function(id) { - return !allModules[id]; - }); - if (newModules.length > 0 || removedModules.length > 0) { - var source = hotUpdateChunkTemplate.render(chunkId, newModules, removedModules, this.hash, this.moduleTemplate, this.dependencyTemplates); - var filename = this.getPath(hotUpdateChunkFilename, { - hash: records.hash, - chunk: currentChunk - }); - this.additionalChunkAssets.push(filename); - this.assets[filename] = source; - hotUpdateMainContent.c[chunkId] = true; - currentChunk.files.push(filename); - this.applyPlugins('chunk-asset', currentChunk, filename); - } - } else { - hotUpdateMainContent.c[chunkId] = false; - } - }, this); - var source = new RawSource(JSON.stringify(hotUpdateMainContent)); - var filename = this.getPath(hotUpdateMainFilename, { - hash: records.hash - }); - this.assets[filename] = source; - }); - - compilation.mainTemplate.plugin('hash', function(hash) { - hash.update('HotMainTemplateDecorator'); - }); - - compilation.mainTemplate.plugin('module-require', function(_, chunk, hash, varModuleId) { - return 'hotCreateRequire(' + varModuleId + ')'; - }); - - compilation.mainTemplate.plugin('require-extensions', function(source) { - var buf = [source]; - buf.push(''); - buf.push('// __webpack_hash__'); - buf.push(this.requireFn + '.h = function() { return hotCurrentHash; };'); - return this.asString(buf); - }); - - compilation.mainTemplate.plugin('bootstrap', function(source, chunk, hash) { - source = this.applyPluginsWaterfall('rax-hot-bootstrap', source, chunk, hash); - - // cross-platform weex this is undefined - return this.asString([ - require('./globalTemplate.js'), - source, - '', - hotInitCode - .replace(/\$require\$/g, this.requireFn) - .replace(/\$hash\$/g, JSON.stringify(hash)) - .replace(/\/\* foreachInstalledChunks \*\//g, chunk.chunks.length > 0 ? 'for(var chunkId in installedChunks)' : 'var chunkId = ' + JSON.stringify(chunk.id) + ';') - ]); - }); - - compilation.mainTemplate.plugin('global-hash', function() { - return true; - }); - - compilation.mainTemplate.plugin('current-hash', function(_, length) { - if (isFinite(length)) - return 'hotCurrentHash.substr(0, ' + length + ')'; - else - return 'hotCurrentHash'; - }); - - compilation.mainTemplate.plugin('module-obj', function(source, chunk, hash, varModuleId) { - return this.asString([ - source + ',', - 'hot: hotCreateModule(' + varModuleId + '),', - 'parents: (hotCurrentParentsTemp = hotCurrentParents, hotCurrentParents = [], hotCurrentParentsTemp),', - 'children: []' - ]); - }); - - params.normalModuleFactory.plugin('parser', function(parser, parserOptions) { - parser.plugin('expression __webpack_hash__', ParserHelpers.toConstantDependency('__webpack_require__.h()')); - parser.plugin('evaluate typeof __webpack_hash__', ParserHelpers.evaluateToString('string')); - parser.plugin('evaluate Identifier module.hot', function(expr) { - return ParserHelpers.evaluateToBoolean(!!this.state.compilation.hotUpdateChunkTemplate)(expr); - }); - parser.plugin('call module.hot.accept', function(expr) { - if (!this.state.compilation.hotUpdateChunkTemplate) return false; - if (expr.arguments.length >= 1) { - var arg = this.evaluateExpression(expr.arguments[0]); - var params = [], - requests = []; - if (arg.isString()) { - params = [arg]; - } else if (arg.isArray()) { - params = arg.items.filter(function(param) { - return param.isString(); - }); - } - if (params.length > 0) { - params.forEach(function(param, idx) { - var request = param.string; - var dep = new ModuleHotAcceptDependency(request, param.range); - dep.optional = true; - dep.loc = Object.create(expr.loc); - dep.loc.index = idx; - this.state.module.addDependency(dep); - requests.push(request); - }.bind(this)); - if (expr.arguments.length > 1) - this.applyPluginsBailResult('hot accept callback', expr.arguments[1], requests); - else - this.applyPluginsBailResult('hot accept without callback', expr, requests); - } - } - }); - parser.plugin('call module.hot.decline', function(expr) { - if (!this.state.compilation.hotUpdateChunkTemplate) return false; - if (expr.arguments.length === 1) { - var arg = this.evaluateExpression(expr.arguments[0]); - var params = []; - if (arg.isString()) { - params = [arg]; - } else if (arg.isArray()) { - params = arg.items.filter(function(param) { - return param.isString(); - }); - } - params.forEach(function(param, idx) { - var dep = new ModuleHotDeclineDependency(param.string, param.range); - dep.optional = true; - dep.loc = Object.create(expr.loc); - dep.loc.index = idx; - this.state.module.addDependency(dep); - }.bind(this)); - } - }); - parser.plugin('expression module.hot', ParserHelpers.skipTraversal); - }); - }); - - compiler.plugin('this-compilation', (compilation) => { - compilation.mainTemplate.apply(new RaxJsonpMainTemplatePlugin()); - }); -}; - -var hotInitCode = Template.getFunctionContent(require('./HotModuleReplacement.runtime.js')); diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/NullFactory.js b/packages/rax-hot-module-replacement-webpack-plugin/src/NullFactory.js deleted file mode 100644 index 1c3372a75..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/NullFactory.js +++ /dev/null @@ -1,12 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; - -class NullFactory { - create(data, callback) { - return callback(); - } -} -module.exports = NullFactory; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/ParserHelpers.js b/packages/rax-hot-module-replacement-webpack-plugin/src/ParserHelpers.js deleted file mode 100644 index cf0daaa88..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/ParserHelpers.js +++ /dev/null @@ -1,76 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; -const path = require('path'); - -const BasicEvaluatedExpression = require('./BasicEvaluatedExpression'); -const ConstDependency = require('./dependencies/ConstDependency'); -const UnsupportedFeatureWarning = require('./UnsupportedFeatureWarning'); - -const ParserHelpers = exports; - -ParserHelpers.addParsedVariableToModule = function(parser, name, expression) { - if (!parser.state.current.addVariable) return false; - var deps = []; - parser.parse(expression, { - current: { - addDependency: function(dep) { - dep.userRequest = name; - deps.push(dep); - } - }, - module: parser.state.module - }); - parser.state.current.addVariable(name, expression, deps); - return true; -}; - -ParserHelpers.requireFileAsExpression = function(context, pathToModule) { - var moduleJsPath = path.relative(context, pathToModule); - if (!/^[A-Z]:/i.test(moduleJsPath)) { - moduleJsPath = './' + moduleJsPath.replace(/\\/g, '/'); - } - return 'require(' + JSON.stringify(moduleJsPath) + ')'; -}; - -ParserHelpers.toConstantDependency = function(value) { - return function constDependency(expr) { - var dep = new ConstDependency(value, expr.range); - dep.loc = expr.loc; - this.state.current.addDependency(dep); - return true; - }; -}; - -ParserHelpers.evaluateToString = function(value) { - return function stringExpression(expr) { - return new BasicEvaluatedExpression().setString(value).setRange(expr.range); - }; -}; - -ParserHelpers.evaluateToBoolean = function(value) { - return function booleanExpression(expr) { - return new BasicEvaluatedExpression().setBoolean(value).setRange(expr.range); - }; -}; - -ParserHelpers.expressionIsUnsupported = function(message) { - return function unsupportedExpression(expr) { - var dep = new ConstDependency('(void 0)', expr.range); - dep.loc = expr.loc; - this.state.current.addDependency(dep); - if (!this.state.module) return; - this.state.module.warnings.push(new UnsupportedFeatureWarning(this.state.module, message)); - return true; - }; -}; - -ParserHelpers.skipTraversal = function skipTraversal() { - return true; -}; - -ParserHelpers.approve = function approve() { - return true; -}; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/RaxJsonpMainTemplate.runtime.js b/packages/rax-hot-module-replacement-webpack-plugin/src/RaxJsonpMainTemplate.runtime.js deleted file mode 100644 index e7653027c..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/RaxJsonpMainTemplate.runtime.js +++ /dev/null @@ -1,82 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -/* globals hotAddUpdateChunk parentHotUpdateCallback document XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ */ -module.exports = function() { - function webpackHotUpdateCallback(chunkId, moreModules) { - // eslint-disable-line no-unused-vars - hotAddUpdateChunk(chunkId, moreModules); - if (parentHotUpdateCallback) parentHotUpdateCallback(chunkId, moreModules); - } // $semicolon - - function hotDownloadUpdateChunk(chunkId) { - // eslint-disable-line no-unused-vars - var isWeex = typeof callNative === 'function'; - var updateFile = $require$.p + $hotChunkFilename$; - if (isWeex) { - fetch(updateFile, { - method: 'GET', - dataType: 'text', - headers: { - 'Content-Type': 'text/javascript' - } - }) - .then(function(response) { - return response.text(); - }) - .then(function(text) { - eval(text); - }) - .catch(function(err) { - throw err; - }); - } else { - var head = document.getElementsByTagName('head')[0]; - var script = document.createElement('script'); - script.type = 'text/javascript'; - script.charset = 'utf-8'; - script.src = updateFile; - head.appendChild(script); - } - } - - function hotDownloadManifest() { - // eslint-disable-line no-unused-vars - return new Promise(function(resolve, reject) { - if (typeof XMLHttpRequest === 'undefined') - return reject(new Error('No browser support jsonp')); - try { - var request = new XMLHttpRequest(); - var requestPath = $require$.p + $hotMainFilename$; - request.open('GET', requestPath, true); - request.timeout = 10000; - request.send(null); - } catch (err) { - return reject(err); - } - request.onreadystatechange = function() { - if (request.readyState !== 4) return; - if (request.status === 0) { - // timeout - reject(new Error('Manifest request to ' + requestPath + ' timed out.')); - } else if (request.status === 404) { - // no update available - resolve(); - } else if (request.status !== 200 && request.status !== 304) { - // other failure - reject(new Error('Manifest request to ' + requestPath + ' failed.')); - } else { - // success - try { - var update = JSON.parse(request.responseText); - } catch (e) { - reject(e); - return; - } - resolve(update); - } - }; - }); - } -}; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/RaxJsonpMainTemplatePlugin.js b/packages/rax-hot-module-replacement-webpack-plugin/src/RaxJsonpMainTemplatePlugin.js deleted file mode 100644 index 317d15493..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/RaxJsonpMainTemplatePlugin.js +++ /dev/null @@ -1,66 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; - -const Template = require('./Template'); - -class JsonpMainTemplatePlugin { - apply(mainTemplate) { - try { - mainTemplate.hooks.hotBootstrap.tap('RaxJsonpMainTemplatePlugin', this.onBootstrap); - mainTemplate.hooks.hash.tap('RaxJsonpMainTemplatePlugin', this.onHash); - } catch (e) { - mainTemplate.plugin('bootstrap', this.onBootstrap); - mainTemplate.plugin('hash', this.onHash); - } - } - - onHash(hash) { - hash.update('jsonp'); - hash.update('4'); - hash.update(`${this.outputOptions.filename}`); - hash.update(`${this.outputOptions.chunkFilename}`); - hash.update(`${this.outputOptions.jsonpFunction}`); - hash.update(`${this.outputOptions.hotUpdateFunction}`); - } - - onBootstrap(source, chunk, hash) { - const hotUpdateChunkFilename = this.outputOptions.hotUpdateChunkFilename; - const hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename; - const hotUpdateFunction = this.outputOptions.hotUpdateFunction; - const currentHotUpdateChunkFilename = this.applyPluginsWaterfall( - 'asset-path', - JSON.stringify(hotUpdateChunkFilename), - { - hash: `" + ${this.renderCurrentHashCode(hash)} + "`, - hashWithLength: length => `" + ${this.renderCurrentHashCode(hash, length)} + "`, - chunk: { - id: '" + chunkId + "' - } - } - ); - const currentHotUpdateMainFilename = this.applyPluginsWaterfall( - 'asset-path', - JSON.stringify(hotUpdateMainFilename), - { - hash: `" + ${this.renderCurrentHashCode(hash)} + "`, - hashWithLength: length => `" + ${this.renderCurrentHashCode(hash, length)} + "` - } - ); - const runtimeSource = Template.getFunctionContent(require('./RaxJsonpMainTemplate.runtime.js')) - .replace(/\/\/\$semicolon/g, ';') - .replace(/\$require\$/g, this.requireFn) - .replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename) - .replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename) - .replace(/\$hash\$/g, JSON.stringify(hash)); - return `${source} -function hotDisposeChunk(chunkId) { -delete installedChunks[chunkId]; -} -var parentHotUpdateCallback = global[${JSON.stringify(hotUpdateFunction)}]; -global[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`; - } -} -module.exports = JsonpMainTemplatePlugin; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/Template.js b/packages/rax-hot-module-replacement-webpack-plugin/src/Template.js deleted file mode 100644 index 4a697fe87..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/Template.js +++ /dev/null @@ -1,166 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; - -const Tapable = require('tapable'); -const ConcatSource = require('webpack-sources').ConcatSource; - -const START_LOWERCASE_ALPHABET_CODE = 'a'.charCodeAt(0); -const START_UPPERCASE_ALPHABET_CODE = 'A'.charCodeAt(0); -const DELTA_A_TO_Z = 'z'.charCodeAt(0) - START_LOWERCASE_ALPHABET_CODE + 1; - -module.exports = class Template extends Tapable { - constructor(outputOptions) { - super(); - this.outputOptions = outputOptions || {}; - } - - static getFunctionContent(fn) { - return fn.toString().replace(/^function\s?\(\)\s?\{\n?|\n?\}$/g, '').replace(/^\t/mg, ''); - } - - static toIdentifier(str) { - if (typeof str !== 'string') return ''; - return str.replace(/^[^a-zA-Z$_]/, '_').replace(/[^a-zA-Z0-9$_]/g, '_'); - } - - static toPath(str) { - if (typeof str !== 'string') return ''; - return str.replace(/[^a-zA-Z0-9_!§$()=\-\^°]+/g, '-').replace(/^-|-$/, ''); - } - - // map number to a single character a-z, A-Z or <_ + number> if number is too big - static numberToIdentifer(n) { - // lower case - if (n < DELTA_A_TO_Z) return String.fromCharCode(START_LOWERCASE_ALPHABET_CODE + n); - - // upper case - n -= DELTA_A_TO_Z; - if (n < DELTA_A_TO_Z) return String.fromCharCode(START_UPPERCASE_ALPHABET_CODE + n); - - // fall back to _ + number - n -= DELTA_A_TO_Z; - return '_' + n; - } - - indent(str) { - if (Array.isArray(str)) { - return str.map(this.indent.bind(this)).join('\n'); - } else { - str = str.trimRight(); - if (!str) return ''; - var ind = str[0] === '\n' ? '' : '\t'; - return ind + str.replace(/\n([^\n])/g, '\n\t$1'); - } - } - - prefix(str, prefix) { - if (Array.isArray(str)) { - str = str.join('\n'); - } - str = str.trim(); - if (!str) return ''; - const ind = str[0] === '\n' ? '' : prefix; - return ind + str.replace(/\n([^\n])/g, '\n' + prefix + '$1'); - } - - asString(str) { - if (Array.isArray(str)) { - return str.join('\n'); - } - return str; - } - - getModulesArrayBounds(modules) { - if (!modules.every(moduleIdIsNumber)) - return false; - var maxId = -Infinity; - var minId = Infinity; - modules.forEach(function(module) { - if (maxId < module.id) maxId = module.id; - if (minId > module.id) minId = module.id; - }); - if (minId < 16 + ('' + minId).length) { - // add minId x ',' instead of 'Array(minId).concat(...)' - minId = 0; - } - var objectOverhead = modules.map(function(module) { - var idLength = (module.id + '').length; - return idLength + 2; - }).reduce(function(a, b) { - return a + b; - }, -1); - var arrayOverhead = minId === 0 ? maxId : 16 + ('' + minId).length + maxId; - return arrayOverhead < objectOverhead ? [minId, maxId] : false; - } - - renderChunkModules(chunk, moduleTemplate, dependencyTemplates, prefix) { - if (!prefix) prefix = ''; - var source = new ConcatSource(); - if (chunk.modules.length === 0) { - source.add('[]'); - return source; - } - var removedModules = chunk.removedModules; - var allModules = chunk.modules.map(function(module) { - return { - id: module.id, - source: moduleTemplate.render(module, dependencyTemplates, chunk) - }; - }); - if (removedModules && removedModules.length > 0) { - removedModules.forEach(function(id) { - allModules.push({ - id: id, - source: 'false' - }); - }); - } - var bounds = this.getModulesArrayBounds(chunk.modules); - - if (bounds) { - // Render a spare array - var minId = bounds[0]; - var maxId = bounds[1]; - if (minId !== 0) source.add('Array(' + minId + ').concat('); - source.add('[\n'); - var modules = {}; - allModules.forEach(function(module) { - modules[module.id] = module; - }); - for (var idx = minId; idx <= maxId; idx++) { - var module = modules[idx]; - if (idx !== minId) source.add(',\n'); - source.add('/* ' + idx + ' */'); - if (module) { - source.add('\n'); - source.add(module.source); - } - } - source.add('\n' + prefix + ']'); - if (minId !== 0) source.add(')'); - } else { - // Render an object - source.add('{\n'); - allModules.sort(function(a, b) { - var aId = a.id + ''; - var bId = b.id + ''; - if (aId < bId) return -1; - if (aId > bId) return 1; - return 0; - }).forEach(function(module, idx) { - if (idx !== 0) source.add(',\n'); - source.add('\n/***/ ' + JSON.stringify(module.id) + ':\n'); - source.add(module.source); - }); - source.add('\n\n' + prefix + '}'); - } - return source; - } -}; - -function moduleIdIsNumber(module) { - return typeof module.id === 'number'; -} diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/UnsupportedFeatureWarning.js b/packages/rax-hot-module-replacement-webpack-plugin/src/UnsupportedFeatureWarning.js deleted file mode 100644 index 97b5065e4..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/UnsupportedFeatureWarning.js +++ /dev/null @@ -1,21 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; - -const WebpackError = require('./WebpackError'); - -class UnsupportedFeatureWarning extends WebpackError { - constructor(module, message) { - super(); - - this.name = 'UnsupportedFeatureWarning'; - this.message = message; - this.origin = this.module = module; - - Error.captureStackTrace(this, this.constructor); - } -} - -module.exports = UnsupportedFeatureWarning; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/WebpackError.js b/packages/rax-hot-module-replacement-webpack-plugin/src/WebpackError.js deleted file mode 100644 index 8ccbd2280..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/WebpackError.js +++ /dev/null @@ -1,11 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Jarid Margolin @jaridmargolin -*/ -'use strict'; - -module.exports = class WebpackError extends Error { - inspect() { - return this.stack + (this.details ? `\n${this.details}` : ''); - } -}; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/compareLocations.js b/packages/rax-hot-module-replacement-webpack-plugin/src/compareLocations.js deleted file mode 100644 index 0aa3085ea..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/compareLocations.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; -module.exports = function compareLocations(a, b) { - if (typeof a === 'string') { - if (typeof b === 'string') { - if (a < b) return -1; - if (a > b) return 1; - return 0; - } else if (typeof b === 'object') { - return 1; - } else { - return 0; - } - } else if (typeof a === 'object') { - if (typeof b === 'string') { - return -1; - } else if (typeof b === 'object') { - if (a.start && b.start) { - const ap = a.start; - const bp = b.start; - if (ap.line < bp.line) return -1; - if (ap.line > bp.line) return 1; - if (ap.column < bp.column) return -1; - if (ap.column > bp.column) return 1; - } - if (a.index < b.index) return -1; - if (a.index > b.index) return 1; - return 0; - } else { - return 0; - } - } -}; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ConstDependency.js b/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ConstDependency.js deleted file mode 100644 index 0d523961e..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ConstDependency.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; -const NullDependency = require('./NullDependency'); - -class ConstDependency extends NullDependency { - constructor(expression, range) { - super(); - this.expression = expression; - this.range = range; - } - - updateHash(hash) { - hash.update(this.range + ''); - hash.update(this.expression + ''); - } -} - -ConstDependency.Template = class ConstDependencyTemplate { - apply(dep, source) { - if (typeof dep.range === 'number') { - source.insert(dep.range, dep.expression); - return; - } - - source.replace(dep.range[0], dep.range[1] - 1, dep.expression); - } -}; - -module.exports = ConstDependency; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleDependency.js b/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleDependency.js deleted file mode 100644 index 852415f6c..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleDependency.js +++ /dev/null @@ -1,23 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; -const Dependency = require('../Dependency'); - -class ModuleDependency extends Dependency { - constructor(request) { - super(); - this.request = request; - this.userRequest = request; - } - - isEqualResource(other) { - if (!(other instanceof ModuleDependency)) - return false; - - return this.request === other.request; - } -} - -module.exports = ModuleDependency; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleDependencyTemplateAsId.js b/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleDependencyTemplateAsId.js deleted file mode 100644 index e261e9627..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleDependencyTemplateAsId.js +++ /dev/null @@ -1,20 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; - -class ModuleDependencyTemplateAsId { - apply(dep, source, outputOptions, requestShortener) { - if (!dep.range) return; - const comment = outputOptions.pathinfo ? - `/*! ${requestShortener.shorten(dep.request)} */ ` : ''; - let content; - if (dep.module) - content = comment + JSON.stringify(dep.module.id); - else - content = require('./WebpackMissingModule').module(dep.request); - source.replace(dep.range[0], dep.range[1] - 1, content); - } -} -module.exports = ModuleDependencyTemplateAsId; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleHotAcceptDependency.js b/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleHotAcceptDependency.js deleted file mode 100644 index 0f251587c..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleHotAcceptDependency.js +++ /dev/null @@ -1,23 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; -const ModuleDependency = require('./ModuleDependency'); -const ModuleDependencyTemplateAsId = require('./ModuleDependencyTemplateAsId'); - -class ModuleHotAcceptDependency extends ModuleDependency { - constructor(request, range) { - super(request); - this.range = range; - this.weak = true; - } - - get type() { - return 'module.hot.accept'; - } -} - -ModuleHotAcceptDependency.Template = ModuleDependencyTemplateAsId; - -module.exports = ModuleHotAcceptDependency; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleHotDeclineDependency.js b/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleHotDeclineDependency.js deleted file mode 100644 index f61f0cacd..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/ModuleHotDeclineDependency.js +++ /dev/null @@ -1,23 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; -const ModuleDependency = require('./ModuleDependency'); -const ModuleDependencyTemplateAsId = require('./ModuleDependencyTemplateAsId'); - -class ModuleHotDeclineDependency extends ModuleDependency { - constructor(request, range) { - super(request); - this.range = range; - this.weak = true; - } - - get type() { - return 'module.hot.decline'; - } -} - -ModuleHotDeclineDependency.Template = ModuleDependencyTemplateAsId; - -module.exports = ModuleHotDeclineDependency; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/NullDependency.js b/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/NullDependency.js deleted file mode 100644 index 0c29b8751..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/NullDependency.js +++ /dev/null @@ -1,24 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; -const Dependency = require('../Dependency'); - -class NullDependency extends Dependency { - get type() { - return 'null'; - } - - isEqualResource() { - return false; - } - - updateHash() {} -} - -NullDependency.Template = class NullDependencyTemplate { - apply() {} -}; - -module.exports = NullDependency; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/PrefetchDependency.js b/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/PrefetchDependency.js deleted file mode 100644 index 277ebf0eb..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/dependencies/PrefetchDependency.js +++ /dev/null @@ -1,18 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -'use strict'; -const ModuleDependency = require('./ModuleDependency'); - -class PrefetchDependency extends ModuleDependency { - constructor(request) { - super(request); - } - - get type() { - return 'prefetch'; - } -} - -module.exports = PrefetchDependency; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/globalTemplate.js b/packages/rax-hot-module-replacement-webpack-plugin/src/globalTemplate.js deleted file mode 100644 index 78fd5d25b..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/globalTemplate.js +++ /dev/null @@ -1,33 +0,0 @@ -const Template = require('./Template'); -const XMLHttpRequestRuntime = Template.getFunctionContent(require('./polyfill/XMLHttpRequest')); - -module.exports = ` -var global; - -if (typeof window !== 'undefined') { - global = window; -} else if (typeof global !== 'undefined') { - global = global; -} else if (typeof self !== 'undefined') { - global = self; -} else { - global = {}; -}; - - -// reload polyfill -var isWeex = typeof callNative === 'function'; - -if (isWeex && typeof location.reload === 'undefined') { - var LOCATION_MODULE = '@weex-module/location'; - - location.reload = function(forceReload) { - var weexLocation = require(LOCATION_MODULE); - weexLocation.reload(forceReload); - }; -}; - -if (typeof XMLHttpRequest === 'undefined') { - ${XMLHttpRequestRuntime} -} -`; diff --git a/packages/rax-hot-module-replacement-webpack-plugin/src/polyfill/XMLHttpRequest.js b/packages/rax-hot-module-replacement-webpack-plugin/src/polyfill/XMLHttpRequest.js deleted file mode 100644 index 4e704d4dc..000000000 --- a/packages/rax-hot-module-replacement-webpack-plugin/src/polyfill/XMLHttpRequest.js +++ /dev/null @@ -1,64 +0,0 @@ -module.exports = function() { - var XMLHttpRequest = function() { // eslint-disable-line - this.UNSENT = 0; - this.OPENED = 1; - this.HEADERS_RECEIVED = 2; - this.LOADING = 3; - this.DONE = 4; - - this.readyState = 0; - this.status = 0; - this.responseHeaders = {}; - this.timeout = 0; - this.onreadystatechange = function() {}; - }; - - XMLHttpRequest.prototype.open = function(method, url, async) { - if (this.readyState !== this.UNSENT) { - throw new Error('Cannot open, already sending'); - } - - if (async !== undefined && !async) { - // async is default - throw new Error('Synchronous http requests are not supported'); - } - - if (!url) { - throw new Error('Cannot load an empty url'); - } - - this._method = method.toUpperCase(); - this._url = url; - this._aborted = false; - this.readyState = 1; - }; - - XMLHttpRequest.prototype.send = function(data) { - if (this.readyState !== this.OPENED) { - throw new Error('Request has not been opened'); - } - if (this._sent) { - throw new Error('Request has already been sent'); - } - this._sent = true; - var self = this; - fetch(this._url, { - method: this._method, - dataType: 'text' - }) - .then(function(response) { - return response.text(); - }) - .then(function(text) { - self.responseText = text; - self.status = 200; - self.readyState = self.DONE; - self.onreadystatechange(); - }) - .catch(function(err) { - self.status = 404; - self.readyState = self.DONE; - self.onreadystatechange(); - }); - }; -}; diff --git a/packages/rax-jest-config/package.json b/packages/rax-jest-config/package.json index a429a1a0b..2843c6cee 100644 --- a/packages/rax-jest-config/package.json +++ b/packages/rax-jest-config/package.json @@ -2,7 +2,7 @@ "name": "rax-jest-config", "version": "1.0.0", "description": "rax jest config", - "main": "src/index.js", + "main": "lib/index.js", "license": "BSD-3-Clause", "repository": { "type": "git", diff --git a/packages/rax-jest-config/src/index.js b/packages/rax-jest-config/src/index.js index 1a8b522c5..d9059c9e2 100644 --- a/packages/rax-jest-config/src/index.js +++ b/packages/rax-jest-config/src/index.js @@ -1,4 +1,4 @@ -module.exports = ({rootDir = process.cwd(), moduleNameMapper = {}} = {}) => { +module.exports = ({ rootDir = process.cwd(), moduleNameMapper = {} } = {}) => { return { rootDir, collectCoverage: true, diff --git a/packages/rax-miniapp-babel-plugins/README-zh.md b/packages/rax-miniapp-babel-plugins/README-zh.md deleted file mode 100644 index f85ac6912..000000000 --- a/packages/rax-miniapp-babel-plugins/README-zh.md +++ /dev/null @@ -1,22 +0,0 @@ -# rax-miniapp-babel-plugins - -
- -[英文](./README.md) - -🚀 我们可以在通过这些 babel 插件更大程度上优化生成的小程序代码。 - -## 为什么需要预编译? - -### Rax 小程序运行时方案 - -#### 原生生命周期 - -在 Rax 小程序运行时解决方案中,我们可以提前知道开发者使用了哪个原生生命周期。过去,我们将注册整个小程序的原生生命周期。这将对性能产生一定影响,甚至导致内存泄漏。 - -#### 使用内置组件 - -在此解决方案中,我们必须遍历小程序的所有内置组件。这将对性能产生一定影响,并生成大量无效代码。但是现在,我们可以在预编译阶段获取此信息。 - -## 更多的 -预编译可以为我们带来更多的优化可能性。我们将继续补充。 diff --git a/packages/rax-miniapp-babel-plugins/README.md b/packages/rax-miniapp-babel-plugins/README.md deleted file mode 100644 index b1689e817..000000000 --- a/packages/rax-miniapp-babel-plugins/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# rax-miniapp-babel-plugins - - - -[简体中文](./README-zh.md) - -🚀 We can optimize the miniapp code to a greater extent by these babel plugins. - -## Why? - -### Rax miniapp runtime solution - -#### Native LifeCycle - -In Rax miniapp runtime solution, we must know in advance which native life cycles developer has used. -In the past, we will register the entire miniapp native life cycle. This will have a certain impact on performance and even lead to memory leaks. - -#### Used Built-in Components - -In this solution, we have to traverse all the built-in components of the miniapp. This will have a certain impact on performance and generate a lot of invalid code. But now, we can get this information in the pre-compilation stage. - -#### Used Native Component or Npm Component wrotten in native - -We can get all component information in the pre-compilation stage. - -## And More -Pre-complie can bring us more optimization possibilities. We will continue to add. diff --git a/packages/rax-miniapp-babel-plugins/package.json b/packages/rax-miniapp-babel-plugins/package.json deleted file mode 100644 index 036fd5584..000000000 --- a/packages/rax-miniapp-babel-plugins/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "rax-miniapp-babel-plugins", - "version": "0.1.8", - "description": "rax miniapp babel plugins", - "main": "src/index.js", - "repository": { - "type": "git", - "url": "git+https://github.com/raxjs/rax-scripts.git" - }, - "keywords": [ - "rax", - "babel", - "babel-plugins" - ], - "author": "Rax Team", - "license": "MIT", - "bugs": { - "url": "https://github.com/raxjs/rax-scripts/issues" - }, - "homepage": "https://github.com/raxjs/rax-scripts#readme", - "dependencies": { - "@babel/code-frame": "^7.8.3", - "fs-extra": "^9.0.1", - "md5": "^2.2.1" - } -} diff --git a/packages/rax-miniapp-babel-plugins/src/constants.js b/packages/rax-miniapp-babel-plugins/src/constants.js deleted file mode 100644 index 79e027549..000000000 --- a/packages/rax-miniapp-babel-plugins/src/constants.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - MINIAPP: 'miniapp', - WECHAT_MINIPROGRAM: 'wechat-miniprogram', - BYTEDANCE_MICROAPP: 'bytedance-microapp', - QUICKAPP: 'quickapp' -}; diff --git a/packages/rax-miniapp-babel-plugins/src/index.js b/packages/rax-miniapp-babel-plugins/src/index.js deleted file mode 100644 index 0964646f1..000000000 --- a/packages/rax-miniapp-babel-plugins/src/index.js +++ /dev/null @@ -1,28 +0,0 @@ -module.exports = function({ usingComponents, nativeLifeCycleMap, target, rootDir, usingPlugins, runtimeDependencies }) { - return [ - require.resolve('./plugins/babel-plugin-remove-Function'), - require.resolve('./plugins/babel-plugin-external-module'), - [ - require.resolve('./plugins/babel-plugin-native-lifecycle'), - { - nativeLifeCycleMap, - }, - ], - [ - require.resolve('./plugins/babel-plugin-handle-native-component'), - { - usingComponents, - target, - rootDir, - runtimeDependencies - } - ], - [ - require.resolve('./plugins/babel-plugin-handle-plugin-component'), - { - usingPlugins - } - ], - - ]; -}; diff --git a/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-external-module.js b/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-external-module.js deleted file mode 100644 index acc832485..000000000 --- a/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-external-module.js +++ /dev/null @@ -1,19 +0,0 @@ -module.exports = function visitor({ types: t }) { - return { - visitor: { - CallExpression(path) { - const { node } = path; - if ( - node.callee.name === 'require' && - node.arguments && - node.arguments.length === 1 && - t.isStringLiteral(node.arguments[0]) && - (node.arguments[0].value.indexOf('@weex-module') > -1 || node.arguments[0].value.indexOf('@system') > -1) - ) { - // Avoid weex and quickapp module effect - path.replaceWith(t.nullLiteral()); - } - } - } - }; -}; diff --git a/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-handle-native-component.js b/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-handle-native-component.js deleted file mode 100644 index ed4a0b920..000000000 --- a/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-handle-native-component.js +++ /dev/null @@ -1,129 +0,0 @@ -const { resolve, dirname, join } = require('path'); -const { existsSync, readJSONSync } = require('fs-extra'); -const extMap = require('../utils/extMap'); -const { collectComponentAttr, collectUsings } = require('../utils/handleComponentAST'); - -const { WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, QUICKAPP } = require('../constants'); - -const RELATIVE_COMPONENTS_REG = /^\./; - -const baseComponents = [ - 'rax-view', - 'rax-canvas', - 'rax-icon', - 'rax-image', - 'rax-picture', - 'rax-text', - 'rax-link', - 'rax-scrollview', - 'rax-recyclerview', - 'rax-slider', - 'rax-textinput', - 'rax-video' -]; - -const targetMap = { - [WECHAT_MINIPROGRAM]: 'wechat', - [BYTEDANCE_MICROAPP]: 'bytedance', - [QUICKAPP]: 'quickapp' -}; - -/** - * Get native component npm path - * @param {string} rootDir project root dir - * @param {string} source module name - * @param {string} target miniapp platform - * @param {string[]} runtimeDependencies components that use runtime implementation - * - */ -function getNpmSourcePath(rootDir, source, target, runtimeDependencies) { - const modulePath = resolve(rootDir, 'node_modules', source); - try { - const pkgConfig = readJSONSync(join(modulePath, 'package.json')); - const miniappConfig = pkgConfig.miniappConfig; - if (!miniappConfig || baseComponents.includes(source) || isInRuntimeDependencies(source, runtimeDependencies)) { - return source; - } - const miniappEntry = target === 'miniapp' ? miniappConfig.main : miniappConfig[`main:${targetMap[target]}`]; - // Ensure component has target platform rax complie result - if (!miniappEntry) { - return source; - } - return join(source, miniappEntry); - } catch (err) { - return source; - } -}; - -function getTmplPath(source, rootDir, dirName, target, runtimeDependencies) { - // If it's a npm module, keep source origin value, otherwise use absolute path - const isNpm = !RELATIVE_COMPONENTS_REG.test(source); - let filePath = isNpm ? getNpmSourcePath(rootDir, source, target, runtimeDependencies) : resolve(dirName, source); - const absPath = isNpm ? resolve(rootDir, 'node_modules', filePath) : filePath; - if (!existsSync(`${absPath}.${extMap[target]}`)) return false; - if (target === 'wechat-miniprogram') { - // In Wechat MiniProgram need remove miniprogram_dist - filePath = filePath.replace('/miniprogram_dist', ''); - } - return isNpm ? filePath : `.${filePath.replace(resolve(rootDir, 'src'), '')}`; -} - -/** - * Judge if the str is regexp - * @param {string} str - */ -function isRegExpStr(str) { - return str[0] === '/' && str[str.length - 1] === '/'; -} - -/** - * - * @param {string} dependency - * @param {string[]} runtimeDependencies - */ -function isInRuntimeDependencies(dependency, runtimeDependencies = []) { - for (let runtimeDependency of runtimeDependencies) { - if (isRegExpStr(runtimeDependency)) { - const reg = new RegExp(runtimeDependency.slice(1, -1)); - if (reg.test(dependency)) return true; - } else if (runtimeDependency === dependency) return true; - } - return false; -} - -module.exports = function visitor( - { types: t }, - { usingComponents, target, rootDir, runtimeDependencies } -) { - // Collect imported dependencies - let nativeComponents = {}; - const scanedPageMap = {}; - return { - visitor: { - Program: { - exit(path, { filename }) { - scanedPageMap[filename] = false; - nativeComponents = {}; - } - }, - ImportDeclaration: { - enter(path, { filename }) { - const { specifiers, source } = path.node; - if (Array.isArray(specifiers) && t.isStringLiteral(source)) { - const dirName = dirname(filename); - const filePath = getTmplPath(source.value, rootDir, dirName, target, runtimeDependencies); - if (filePath) { - if (!scanedPageMap[filename]) { - scanedPageMap[filename] = true; - path.parentPath.traverse({ - JSXOpeningElement: collectComponentAttr(nativeComponents, t) - }); - } - collectUsings(path, nativeComponents, usingComponents, filePath, t); - } - } - }, - } - }, - }; -}; diff --git a/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-handle-plugin-component.js b/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-handle-plugin-component.js deleted file mode 100644 index e3ade88b2..000000000 --- a/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-handle-plugin-component.js +++ /dev/null @@ -1,46 +0,0 @@ -const { - collectComponentAttr, - collectUsings, -} = require('../utils/handleComponentAST'); - -const MINIAPP_PLUGIN_COMPONENTS_REG = /^plugin\:\/\//; - -module.exports = function visitor({ types: t }, { usingPlugins }) { - // Collect imported dependencies - let pluginComponents = {}; - const scanedFileMap = {}; - - return { - visitor: { - Program: { - exit(path, { filename }) { - scanedFileMap[filename] = false; - pluginComponents = {}; - }, - }, - ImportDeclaration: { - enter(path, { filename }) { - const { source } = path.node; - if ( - t.isStringLiteral(source) && - MINIAPP_PLUGIN_COMPONENTS_REG.test(source.value) - ) { - if (!scanedFileMap[filename]) { - scanedFileMap[filename] = true; - path.parentPath.traverse({ - JSXOpeningElement: collectComponentAttr(pluginComponents, t), - }); - } - collectUsings( - path, - pluginComponents, - usingPlugins, - source.value, - t - ); - } - }, - }, - }, - }; -}; diff --git a/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-native-lifecycle.js b/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-native-lifecycle.js deleted file mode 100644 index bca887333..000000000 --- a/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-native-lifecycle.js +++ /dev/null @@ -1,27 +0,0 @@ -const CodeError = require('../utils/CodeError'); -const getPagePath = require('../utils/getPagePath'); - -module.exports = function visitor({ types: t }, { nativeLifeCycleMap }) { - return { - visitor: { - CallExpression(path, { filename, file: { code } }) { - const pagePath = getPagePath(filename); - if (pagePath) { - const nativeLifeCycle = nativeLifeCycleMap[pagePath]; - if (t.isIdentifier(path.node.callee, { - name: 'registerNativeEventListeners' - })) { - if (t.isArrayExpression(path.node.arguments[1])) { - path.node.arguments[1].elements.forEach(element => { - nativeLifeCycle[element.value] = true; - }); - } else { - throw new CodeError(code, path.node.loc, - "registerNativeEventListeners's second argument should be an array, like ['onReachBottom']"); - } - } - } - } - } - }; -}; diff --git a/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-remove-Function.js b/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-remove-Function.js deleted file mode 100644 index a976d6f4f..000000000 --- a/packages/rax-miniapp-babel-plugins/src/plugins/babel-plugin-remove-Function.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = function visitor() { - return { - visitor: { - CallExpression(path) { - const { node } = path; - const callee = node.callee.callee; - if ( - callee && - callee.name === 'Function' && - node.callee.arguments && - node.callee.arguments.length === 2 && - node.callee.arguments[0].value === 'r' && - node.callee.arguments[1].value === 'regeneratorRuntime = r' - ) { - // Remove `Function('r', 'regeneratorRuntime = r')(runtime)` - // Because Alibaba Miniapp doesn't allow use `Function` - try { - path.parentPath.remove(); - } catch (err) {} - } - } - } - }; -}; diff --git a/packages/rax-miniapp-babel-plugins/src/utils/CodeError.js b/packages/rax-miniapp-babel-plugins/src/utils/CodeError.js deleted file mode 100644 index 6255cdde1..000000000 --- a/packages/rax-miniapp-babel-plugins/src/utils/CodeError.js +++ /dev/null @@ -1,17 +0,0 @@ -const { codeFrameColumns } = require('@babel/code-frame'); - -function createErrorMessage(sourceCode, loc, extraMessage) { - try { - return codeFrameColumns(sourceCode, loc, { highlightCode: true, message: extraMessage }); - } catch (err) { - return 'Failed to locate source code position.'; - } -} - -class CodeError extends Error { - constructor(sourceCode, loc, message) { - super('\n' + createErrorMessage(sourceCode, loc, message)); - } -} - -module.exports = CodeError; diff --git a/packages/rax-miniapp-babel-plugins/src/utils/extMap.js b/packages/rax-miniapp-babel-plugins/src/utils/extMap.js deleted file mode 100644 index 31325f16d..000000000 --- a/packages/rax-miniapp-babel-plugins/src/utils/extMap.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - 'miniapp': 'axml', - 'wechat-miniprogram': 'wxml', - 'bytedance-microapp': 'ttml', - 'quickapp': 'ux', -}; diff --git a/packages/rax-miniapp-babel-plugins/src/utils/getFilePath.js b/packages/rax-miniapp-babel-plugins/src/utils/getFilePath.js deleted file mode 100644 index 86844e244..000000000 --- a/packages/rax-miniapp-babel-plugins/src/utils/getFilePath.js +++ /dev/null @@ -1,5 +0,0 @@ -const { extname } = require('path'); - -module.exports = function(resourcePath) { - return resourcePath.replace(extname(resourcePath), ''); -}; diff --git a/packages/rax-miniapp-babel-plugins/src/utils/getPagePath.js b/packages/rax-miniapp-babel-plugins/src/utils/getPagePath.js deleted file mode 100644 index d952a1806..000000000 --- a/packages/rax-miniapp-babel-plugins/src/utils/getPagePath.js +++ /dev/null @@ -1,13 +0,0 @@ -const { sep } = require('path'); -const getFilePath = require('./getFilePath'); - -/** - * @param {string} filename - Current handled file name - * @return {string|undefined} - */ -module.exports = function(filename) { - const nodeModulesReg = new RegExp(`\\${sep}node_modules\\${sep}`); - if (!nodeModulesReg.exec(filename)) { - return getFilePath(filename); - } -}; diff --git a/packages/rax-miniapp-babel-plugins/src/utils/getTagName.js b/packages/rax-miniapp-babel-plugins/src/utils/getTagName.js deleted file mode 100644 index 82f9d1f99..000000000 --- a/packages/rax-miniapp-babel-plugins/src/utils/getTagName.js +++ /dev/null @@ -1,5 +0,0 @@ -const md5 = require('md5'); - -module.exports = function getTagName(str) { - return 'c' + md5(str).slice(0, 6); -}; diff --git a/packages/rax-miniapp-babel-plugins/src/utils/handleComponentAST.js b/packages/rax-miniapp-babel-plugins/src/utils/handleComponentAST.js deleted file mode 100644 index 2526a8865..000000000 --- a/packages/rax-miniapp-babel-plugins/src/utils/handleComponentAST.js +++ /dev/null @@ -1,89 +0,0 @@ -const getTagName = require('./getTagName'); - -function collectComponentAttr(components, t) { - return (innerPath) => { - const { node: innerNode } = innerPath; - if (t.isJSXIdentifier(innerNode.name)) { - const tagName = innerNode.name.name; - if (!components[tagName]) { - components[tagName] = { - props: [], - events: [], - node: innerNode, - }; - } - innerNode.attributes.forEach((attrNode) => { - if (!t.isJSXIdentifier(attrNode.name)) return; - const attrName = attrNode.name.name; - if ( - !components[tagName].props.includes(attrName) && - !components[tagName].events.includes(attrName) - ) { - // If it starts with 'on', it must be an event handler - if (/^on/.test(attrName)) { - components[tagName].events.push(attrName.slice(2)); - } else { - components[tagName].props.push(attrName); - } - } - }); - } - }; -} - -function collectUsings( - path, - components, - usings, - filePath, - t -) { - const { specifiers } = path.node; - for (let specifier of specifiers) { - const tagName = specifier.local.name; - const componentInfo = components[tagName]; - if (componentInfo) { - // Insert a tag - componentInfo.node.attributes.push( - t.jsxAttribute( - t.jsxIdentifier('__native'), - t.jsxExpressionContainer(t.booleanLiteral(true)) - ) - ); - - // Generate a random tag name - const replacedTagName = getTagName(tagName); - if (!usings[replacedTagName]) { - usings[replacedTagName] = { props: [], events: [] }; - } - usings[replacedTagName] = { - path: filePath, - props: [ - ...new Set(componentInfo.props.concat(usings[replacedTagName].props)), - ], - events: [ - ...new Set( - componentInfo.events.concat(usings[replacedTagName].events) - ), - ], - }; - // Use const Custom = 'c90589c' replace import Custom from '../public/xxx or plugin://...' - path.replaceWith( - t.VariableDeclaration('const', [ - t.VariableDeclarator( - t.identifier(tagName), - t.stringLiteral(replacedTagName) - ), - ]) - ); - break; - } else { - path.remove(); - } - } -} - -module.exports = { - collectComponentAttr, - collectUsings, -}; diff --git a/packages/rax-miniapp-config-webpack-plugin/package.json b/packages/rax-miniapp-config-webpack-plugin/package.json deleted file mode 100644 index baacfc27e..000000000 --- a/packages/rax-miniapp-config-webpack-plugin/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "rax-miniapp-config-webpack-plugin", - "version": "1.2.3", - "description": "miniapp config webpack plugin", - "main": "src/index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "Rax Team", - "license": "MIT", - "dependencies": { - "fs-extra": "^8.1.0" - } -} diff --git a/packages/rax-miniapp-config-webpack-plugin/src/adaptConfig.js b/packages/rax-miniapp-config-webpack-plugin/src/adaptConfig.js deleted file mode 100644 index 2a2da4d34..000000000 --- a/packages/rax-miniapp-config-webpack-plugin/src/adaptConfig.js +++ /dev/null @@ -1,98 +0,0 @@ -const { MINIAPP, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, QUICKAPP } = require('./constants'); - -const configKeyMap = { - [MINIAPP]: { - window: { - title: 'defaultTitle', - pullRefresh: 'pullRefresh', - titleBarColor: 'titleBarColor' - }, - tabBar: { - textColor: 'textColor', - items: 'items' - }, - items: { - name: 'name', - icon: 'icon', - activeIcon: 'activeIcon', - path: 'pagePath' - } - }, - [WECHAT_MINIPROGRAM]: { - window: { - title: 'navigationBarTitleText', - pullRefresh: 'enablePullDownRefresh', - titleBarColor: 'navigationBarBackgroundColor' - }, - tabBar: { - textColor: 'color', - items: 'list' - }, - items: { - name: 'text', - icon: 'iconPath', - activeIcon: 'selectedIconPath', - path: 'pagePath' - } - }, - [BYTEDANCE_MICROAPP]: { - window: { - title: 'navigationBarTitleText', - pullRefresh: 'enablePullDownRefresh', - titleBarColor: 'navigationBarBackgroundColor' - }, - tabBar: { - textColor: 'color', - items: 'list' - }, - items: { - name: 'text', - icon: 'iconPath', - activeIcon: 'selectedIconPath', - path: 'pagePath' - } - }, - [QUICKAPP]: { - window: { - title: 'titleBarText', - titleBarColor: 'titleBarTextColor' - } - } -}; - -const configValueMap = { - [MINIAPP]: { - window: { - pullRefresh: { - true: 'YES', - false: 'NO' - } - } - } -}; - -module.exports = function adaptConfig(originalConfig, property, target) { - const config = {}; - const configKeyAdapter = - configKeyMap[target] && configKeyMap[target][property]; - const configValueAdapter = - configValueMap[target] && configValueMap[target][property]; - Object.keys(originalConfig).forEach(configKey => { - // configKey, like title - let key = configKey; - let value = originalConfig[configKey]; - if ( - configKeyAdapter && - configKeyAdapter[configKey] && - configKey !== configKeyAdapter[configKey] - ) { - key = configKeyAdapter[configKey]; - } - if (configValueAdapter && configValueAdapter[configKey]) { - value = configValueAdapter[configKey][value]; - } - config[key] = value; - }); - - return config; -}; diff --git a/packages/rax-miniapp-config-webpack-plugin/src/constants.js b/packages/rax-miniapp-config-webpack-plugin/src/constants.js deleted file mode 100644 index 79e027549..000000000 --- a/packages/rax-miniapp-config-webpack-plugin/src/constants.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - MINIAPP: 'miniapp', - WECHAT_MINIPROGRAM: 'wechat-miniprogram', - BYTEDANCE_MICROAPP: 'bytedance-microapp', - QUICKAPP: 'quickapp' -}; diff --git a/packages/rax-miniapp-config-webpack-plugin/src/handleIcon.js b/packages/rax-miniapp-config-webpack-plugin/src/handleIcon.js deleted file mode 100644 index d8ca8e84c..000000000 --- a/packages/rax-miniapp-config-webpack-plugin/src/handleIcon.js +++ /dev/null @@ -1,18 +0,0 @@ -const { dirname, join } = require('path'); -const { copy, existsSync, ensureDirSync } = require('fs-extra'); - -function isUrl(src) { - return /^(https?:)?\/\//.test(src); -} - -module.exports = function(path, outputPath) { - if (!isUrl(path)) { - const sourcePath = join(process.cwd(), 'src', path); - if (existsSync(sourcePath)) { - const distPath = join(outputPath, path); - ensureDirSync(dirname(distPath)); - copy(sourcePath, distPath); - } - } - return path; -}; diff --git a/packages/rax-miniapp-config-webpack-plugin/src/index.js b/packages/rax-miniapp-config-webpack-plugin/src/index.js deleted file mode 100644 index 74dc0c1de..000000000 --- a/packages/rax-miniapp-config-webpack-plugin/src/index.js +++ /dev/null @@ -1,48 +0,0 @@ -const transformAppConfig = require('./transformAppConfig'); -const { join } = require('path'); -const { ensureDirSync } = require('fs-extra'); -const safeWriteFile = require('./safeWriteFile'); -const adaptConfig = require('./adaptConfig'); -const transformNativeConfig = require('./transformNativeConfig'); - -const PluginName = 'MiniAppConfigPlugin'; - -module.exports = class MiniAppConfigPlugin { - constructor(passedOptions) { - this.options = passedOptions; - } - apply(compiler) { - // Currently there is no watch app.json capacity, so use first render flag handle repeatly write config - let isFirstRender = true; - let { outputPath, appConfig, target, type, getAppConfig, nativeConfig } = this.options; - compiler.hooks.beforeCompile.tapAsync(PluginName, (compilation, callback) => { - if (isFirstRender) { - transformConfig(compilation, callback); - isFirstRender = false; - } else { - callback(); - } - }); - - function transformConfig(compilation, callback) { - const config = transformAppConfig(outputPath, appConfig, target); - safeWriteFile(join(outputPath, 'app.json'), config, true); - if (type === 'complie') { - safeWriteFile(join(outputPath, target === 'quickapp' ? 'appConfig.js' : 'app.config.js'), `module.exports = ${JSON.stringify(appConfig, null, 2)}`); - } - // Transform page config - appConfig.routes.map((route) => { - if (route && route.window) { - ensureDirSync(outputPath); - safeWriteFile(join(outputPath, route.source + '.json'), adaptConfig(route.window, 'window', target), true); - } - }); - - // Transform native config - transformNativeConfig(outputPath, nativeConfig, target); - callback(); - } - } -}; - - diff --git a/packages/rax-miniapp-config-webpack-plugin/src/safeWriteFile.js b/packages/rax-miniapp-config-webpack-plugin/src/safeWriteFile.js deleted file mode 100644 index 233b64b10..000000000 --- a/packages/rax-miniapp-config-webpack-plugin/src/safeWriteFile.js +++ /dev/null @@ -1,18 +0,0 @@ -const { dirname } = require('path'); -const { writeFileSync, writeJSONSync, ensureDirSync } = require('fs-extra'); - -/** - * @param {string} outputPath - file outputPath - * @param {string} content - file content - * @param {boolean} isJSON - wheater json file - */ -module.exports = function(outputPath, content, isJSON) { - ensureDirSync(dirname(outputPath)); - if (isJSON) { - writeJSONSync(outputPath, content, { - spaces: 2 - }); - } else { - writeFileSync(outputPath, content); - } -}; diff --git a/packages/rax-miniapp-config-webpack-plugin/src/transformAppConfig.js b/packages/rax-miniapp-config-webpack-plugin/src/transformAppConfig.js deleted file mode 100644 index 266db940d..000000000 --- a/packages/rax-miniapp-config-webpack-plugin/src/transformAppConfig.js +++ /dev/null @@ -1,45 +0,0 @@ -const { resolve } = require('path'); -const { copy } = require('fs-extra'); -const adaptAppConfig = require('./adaptConfig'); -const handleIcon = require('./handleIcon'); - -module.exports = function transformAppConfig(outputPath, originalAppConfig, target) { - const appConfig = {}; - for (let configKey in originalAppConfig) { - const config = originalAppConfig[configKey]; - switch (configKey) { - case 'routes': - // filter routes - break; - case 'window': - appConfig[configKey] = adaptAppConfig(config, 'window', target); - break; - case 'tabBar': - // Handle tab item - if (config.items) { - config.items = config.items.map(itemConfig => { - if (itemConfig.icon) { - itemConfig.icon = handleIcon(itemConfig.icon, outputPath); - } - if (itemConfig.activeIcon) { - itemConfig.activeIcon = handleIcon(itemConfig.activeIcon, outputPath); - } - return adaptAppConfig(itemConfig, 'items', target); - }); - } - // Handle custom tabBar - if (config.custom && typeof config.custom === 'string') { - // Custom tab bar should be native component - copy(resolve('src', config.custom), resolve(outputPath, 'custom-tab-bar')); - config.custom = true; - } - appConfig[configKey] = adaptAppConfig(config, 'tabBar', target); - break; - default: - appConfig[configKey] = config; - break; - } - } - - return appConfig; -}; diff --git a/packages/rax-miniapp-config-webpack-plugin/src/transformNativeConfig.js b/packages/rax-miniapp-config-webpack-plugin/src/transformNativeConfig.js deleted file mode 100644 index 0decaa44b..000000000 --- a/packages/rax-miniapp-config-webpack-plugin/src/transformNativeConfig.js +++ /dev/null @@ -1,16 +0,0 @@ -const { join } = require('path'); - -const safeWriteFile = require('./safeWriteFile'); -const { MINIAPP, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, QUICKAPP } = require('./constants'); - -const fileNameMap = { - [MINIAPP]: 'mini.project.json', - [WECHAT_MINIPROGRAM]: 'project.config.json', - [BYTEDANCE_MICROAPP]: 'project.config.json' -}; - -module.exports = function(outputPath, nativeConfig, target) { - if (nativeConfig && fileNameMap[target]) { - safeWriteFile(join(outputPath, fileNameMap[target]), nativeConfig, true); - } -}; diff --git a/packages/rax-miniapp-runtime-webpack-plugin/package.json b/packages/rax-miniapp-runtime-webpack-plugin/package.json deleted file mode 100644 index a92d36110..000000000 --- a/packages/rax-miniapp-runtime-webpack-plugin/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "rax-miniapp-runtime-webpack-plugin", - "version": "1.2.0", - "description": "A webpack plugin for miniapp runtime build", - "main": "src/index.js", - "keywords": [ - "rax", - "plugin", - "webpack", - "miniapp", - "runtime" - ], - "license": "MIT", - "dependencies": { - "chalk": "^3.0.0", - "colors": "^1.4.0", - "csso": "^4.0.3", - "ejs": "^3.1.2", - "fs-extra": "^8.1.0", - "path-to-regexp": "^3.0.0", - "postcss": "^7.0.17", - "pretty-data": "^0.40.0", - "terser": "^4.6.10", - "webpack": "^4.35.3", - "webpack-sources": "^1.3.0" - } -} diff --git a/packages/rax-miniapp-runtime-webpack-plugin/src/adapter.js b/packages/rax-miniapp-runtime-webpack-plugin/src/adapter.js deleted file mode 100644 index b13e3cde9..000000000 --- a/packages/rax-miniapp-runtime-webpack-plugin/src/adapter.js +++ /dev/null @@ -1,34 +0,0 @@ -const { MINIAPP, WECHAT_MINIPROGRAM } = require('./constants'); - -module.exports = { - [MINIAPP]: { - name: 'Alibaba MiniApp', - APINamespace: 'my', - npmDirName: 'node_modules', - fileName: 'ali', - css: 'acss', - xml: 'axml', - script: 'sjs', - directive: { - prefix: 'a', - if: 'a:if', - elif: 'a:alif', - event: 'on' - }, - }, - [WECHAT_MINIPROGRAM]: { - name: 'Wechat MiniProgram', - APINamespace: 'wx', - npmDirName: 'miniprogram_npm', - fileName: 'wechat', - css: 'wxss', - xml: 'wxml', - script: 'wxs', - directive: { - prefix: 'wx', - if: 'wx:if', - elif: 'wx:alif', - event: 'bind' - }, - }, -}; diff --git a/packages/rax-miniapp-runtime-webpack-plugin/src/constants.js b/packages/rax-miniapp-runtime-webpack-plugin/src/constants.js deleted file mode 100644 index fb0a36293..000000000 --- a/packages/rax-miniapp-runtime-webpack-plugin/src/constants.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - MINIAPP: 'miniapp', - WECHAT_MINIPROGRAM: 'wechat-miniprogram', - VENDOR_CSS_FILE_NAME: 'vendor.css' -}; diff --git a/packages/rax-miniapp-runtime-webpack-plugin/src/generators/app.js b/packages/rax-miniapp-runtime-webpack-plugin/src/generators/app.js deleted file mode 100644 index be85ac129..000000000 --- a/packages/rax-miniapp-runtime-webpack-plugin/src/generators/app.js +++ /dev/null @@ -1,74 +0,0 @@ -const { resolve, relative, extname } = require('path'); -const { readFileSync } = require('fs-extra'); -const ejs = require('ejs'); -const adapter = require('../adapter'); -const { MINIAPP } = require('../constants'); -const addFileToCompilation = require('../utils/addFileToCompilation'); -const getAssetPath = require('../utils/getAssetPath'); -const adjustCSS = require('../utils/adjustCSS'); - -function generateAppJS( - compilation, - commonAppJSFilePaths, - { target, command, rootDir } -) { - const appJsTmpl = readFileSync( - resolve(rootDir, 'templates', 'app.js.ejs'), - 'utf-8' - ); - const appJsContent = ejs.render(appJsTmpl, { - init: `function init(window, document) {${commonAppJSFilePaths - .map( - filePath => - `require('${getAssetPath( - relative(target, filePath), - 'app.js' - )}')(window, document)` - ) - .join(';')}}`, - isMiniApp: target === MINIAPP - }); - addFileToCompilation(compilation, { - filename: 'app.js', - content: appJsContent, - target, - command, - }); -} - -function generateAppCSS(compilation, { target, command, rootDir }) { - // Add default css file to compilation - const defaultCSSTmpl = adjustCSS(readFileSync( - resolve(rootDir, 'templates', 'default.css.ejs'), - 'utf-8' - )); - addFileToCompilation(compilation, { - filename: `default.${adapter[target].css}`, - content: defaultCSSTmpl, - target, - command, - }); - - delete compilation.assets[`${target}/app.css`]; - - let content = '@import "./default";'; - - Object.keys(compilation.assets).forEach(asset => { - if (asset.indexOf(`${target}/index`) > -1 && extname(asset) === '.css') { - content += `@import "./${relative(target, asset)}";`; - delete compilation.assets[asset]; - } - }); - - addFileToCompilation(compilation, { - filename: `app.${adapter[target].css}`, - content, - target, - command, - }); -} - -module.exports = { - generateAppJS, - generateAppCSS -}; diff --git a/packages/rax-miniapp-runtime-webpack-plugin/src/generators/config.js b/packages/rax-miniapp-runtime-webpack-plugin/src/generators/config.js deleted file mode 100644 index 33f4b213a..000000000 --- a/packages/rax-miniapp-runtime-webpack-plugin/src/generators/config.js +++ /dev/null @@ -1,33 +0,0 @@ -const addFileToCompilation = require('../utils/addFileToCompilation'); - -module.exports = function(compilation, { usingComponents, usingPlugins, pages, target, command }) { - const config = { - usingComponents: {}, - usingPlugins: {}, - pages - }; - - if (process.env.DEBUG === 'true') { - config.debug = true; - } - - Object.keys(usingComponents).forEach(name => { - config.usingComponents[name] = { - props: usingComponents[name].props, - events: usingComponents[name].events, - }; - }); - - Object.keys(usingPlugins).forEach(name => { - config.usingPlugins[name] = { - props: usingPlugins[name].props, - events: usingPlugins[name].events, - }; - }); - addFileToCompilation(compilation, { - filename: 'config.js', - content: `module.exports = ${JSON.stringify(config)}`, - command, - target, - }); -}; diff --git a/packages/rax-miniapp-runtime-webpack-plugin/src/generators/element.js b/packages/rax-miniapp-runtime-webpack-plugin/src/generators/element.js deleted file mode 100644 index 3b0e58199..000000000 --- a/packages/rax-miniapp-runtime-webpack-plugin/src/generators/element.js +++ /dev/null @@ -1,81 +0,0 @@ -const ejs = require('ejs'); -const { MINIAPP } = require('../constants'); -const adapter = require('../adapter'); -const addFileToCompilation = require('../utils/addFileToCompilation'); -const getTemplate = require('../utils/getTemplate'); -const { generateRootTmpl } = require('./root'); - -function generateElementJS(compilation, - { target, command, rootDir }) { - addFileToCompilation(compilation, { - filename: 'comp.js', - content: `const render = require('./render'); - - Component(render.createElementConfig());`, - target, - command, - }); -} - -function generateElementTemplate(compilation, - { usingPlugins, usingComponents, target, command, rootDir }) { - let content = '