增加了oakGetPackageJsonVersion的注入插件

This commit is contained in:
Xu Chang 2025-01-26 16:49:22 +08:00
parent aad5f0c6f4
commit 69c1accff2
5 changed files with 34 additions and 2 deletions

View File

@ -0,0 +1,27 @@
const { join } = require('path');
const t = require('@babel/types');
const { assert } = require('console');
module.exports = (babel) => {
return {
visitor: {
FunctionDeclaration(path, state) {
const { cwd } = state;
const { node } = path;
if (t.isIdentifier(node.id) && node.id.name === 'oakGetPackageJsonVersion') {
const { body } = node;
assert(t.isBlockStatement(body));
assert(body.body.length === 1);
const pkgJson = join(cwd, 'package.json');
const { version } = require(pkgJson);
body.body = [
t.returnStatement(t.stringLiteral(version))
];
}
},
},
};
};

View File

@ -26,6 +26,7 @@ const createEnvironmentHash = require('./webpack/persistentCache/createEnvironme
const oakI18nPlugin = require('../babel-plugin/oakI18n'); const oakI18nPlugin = require('../babel-plugin/oakI18n');
const oakPathPlugin = require('../babel-plugin/oakPath'); const oakPathPlugin = require('../babel-plugin/oakPath');
const reuseOakComponentPlugin = require('../babel-plugin/reuse-oak-component');
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false'; const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
const shouldAnalyze = process.env.COMPILE_ANALYZE === 'true'; const shouldAnalyze = process.env.COMPILE_ANALYZE === 'true';
@ -242,7 +243,7 @@ module.exports = function (webpackEnv) {
), ),
loader: 'babel-loader', loader: 'babel-loader',
options: { options: {
plugins: [oakI18nPlugin, oakPathPlugin], plugins: [oakI18nPlugin, oakPathPlugin, reuseOakComponentPlugin],
}, },
}, },
{ {

View File

@ -27,6 +27,7 @@ const { injectGetRender } = require('../utils/injectGetRender');
const oakPathTsxPlugin = require('../babel-plugin/oakPath'); const oakPathTsxPlugin = require('../babel-plugin/oakPath');
const oakRenderNativePlugin = require('../babel-plugin/oakRenderNative'); const oakRenderNativePlugin = require('../babel-plugin/oakRenderNative');
const oakI18nPlugin = require('../babel-plugin/oakI18n'); const oakI18nPlugin = require('../babel-plugin/oakI18n');
const reuseOakComponentPlugin = require('../babel-plugin/reuse-oak-component');
async function renderToCSS({ src, filename, options = {} }) { async function renderToCSS({ src, filename, options = {} }) {
const { lessOptions = {} } = options; const { lessOptions = {} } = options;
@ -56,7 +57,7 @@ function transform({ filename, options, plugins, src }) {
cwd: options.projectRoot, cwd: options.projectRoot,
highlightCode: true, highlightCode: true,
filename, filename,
plugins: plugins.concat([replaceEnvExpressionPlugin, oakPathTsxPlugin, oakRenderNativePlugin, oakI18nPlugin]), plugins: plugins.concat([replaceEnvExpressionPlugin, oakPathTsxPlugin, oakRenderNativePlugin, oakI18nPlugin, reuseOakComponentPlugin]),
sourceType: "module", sourceType: "module",
// NOTE(EvanBacon): We split the parse/transform steps up to accommodate // NOTE(EvanBacon): We split the parse/transform steps up to accommodate
// Hermes parsing, but this defaults to cloning the AST which increases // Hermes parsing, but this defaults to cloning the AST which increases

View File

@ -31,6 +31,7 @@ const createEnvironmentHash = require('./webpack/persistentCache/createEnvironme
const oakPathTsxPlugin = require('../babel-plugin/oakPath'); const oakPathTsxPlugin = require('../babel-plugin/oakPath');
const oakRenderTsxPlugin = require('../babel-plugin/oakRender'); const oakRenderTsxPlugin = require('../babel-plugin/oakRender');
const oakGetAppVersionPlugin = require('../babel-plugin/oakGetAppVersion');
// const oakRouterPlugin = require('../babel-plugin/oakRouter2'); // const oakRouterPlugin = require('../babel-plugin/oakRouter2');
const oakI18nPlugin = require('../babel-plugin/oakI18n'); const oakI18nPlugin = require('../babel-plugin/oakI18n');
const oakStylePlugin = require('../babel-plugin/oakStyle'); const oakStylePlugin = require('../babel-plugin/oakStyle');
@ -609,6 +610,7 @@ module.exports = function (webpackEnv) {
oakRenderTsxPlugin, oakRenderTsxPlugin,
// oakRouterPlugin, // oakRouterPlugin,
oakI18nPlugin, oakI18nPlugin,
oakGetAppVersionPlugin,
reuseOakComponentPlugin, reuseOakComponentPlugin,
// [ // [
// 'import', // 'import',

View File

@ -11,6 +11,7 @@ import { FeatureDict } from '@project/features';
import { AFD } from '@project/types/RuntimeCxt'; import { AFD } from '@project/types/RuntimeCxt';
import { OakApplicationLoadingException, OakHasToVerifyPassword, OakPasswordUnset, OakUserInfoLoadingException } from 'oak-general-business'; import { OakApplicationLoadingException, OakHasToVerifyPassword, OakPasswordUnset, OakUserInfoLoadingException } from 'oak-general-business';
// import { OakUserInfoLoadingException, OakApplicationLoadingException } from 'oak-general-business'; // import { OakUserInfoLoadingException, OakApplicationLoadingException } from 'oak-general-business';
import { MessageProps } from 'oak-frontend-base';
function showMessage(reason: OakException<any>, features: AFD, type?: MessageProps['type']) { function showMessage(reason: OakException<any>, features: AFD, type?: MessageProps['type']) {
const { message, _module, params} = reason; const { message, _module, params} = reason;