Skip to content

Commit 17c8307

Browse files
committed
fix: support component monorepo publish
1 parent 3c81a65 commit 17c8307

5 files changed

Lines changed: 26 additions & 14 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pri",
3-
"version": "3.2.7-beta.26",
3+
"version": "3.2.7-beta.27",
44
"types": "src/node/index.ts",
55
"main": "built/node/index.js",
66
"scripts": {

src/built-in-plugins/command-publish/plugin/run-publish.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export const publish = async (options: PublishOption) => {
2525
await pri.project.ensureProjectFiles();
2626
await pri.project.checkProjectFiles();
2727

28+
const currentSelectedSourceType = pri.selectedSourceType;
29+
2830
if (!options.skipLint) {
2931
await pri.project.lint({
3032
lintAll: true,
@@ -57,7 +59,7 @@ export const publish = async (options: PublishOption) => {
5759
await buildDeclaration();
5860
}
5961

60-
await publishByPackageName(pri.selectedSourceType, options, depMap);
62+
await publishByPackageName(currentSelectedSourceType, options, depMap);
6163

6264
await fs.remove(path.join(pri.projectRootPath, tempPath.dir, declarationPath.dir));
6365
}
@@ -92,6 +94,7 @@ async function publishByPackageName(sourceType: string, options: PublishOption,
9294
// Change source config here
9395
pri.sourceConfig = targetConfig;
9496
pri.sourceRoot = targetRoot;
97+
pri.selectedSourceType = sourceType;
9598

9699
if (!targetPackageJson.name) {
97100
logFatal(`No name found in ${sourceType} package.json`);

src/utils/ensure-files.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as yargs from 'yargs';
55
import { logInfo, logWarn, logFatal } from './log';
66
import { plugin } from './plugins';
77
import { priEvent } from './pri-events';
8+
import { freshGlobalState, globalState } from './global-state';
89

910
export const ensureFiles = async () => {
1011
if (yargs.argv.light) {
@@ -27,6 +28,9 @@ export const ensureFiles = async () => {
2728
);
2829
}),
2930
);
31+
32+
// Fresh package.json
33+
await freshGlobalState(globalState.selectedSourceType);
3034
};
3135

3236
export async function ensureFile(filePath: string, pipeContents: ((prev: string) => string | Promise<string>)[]) {

src/utils/global-state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function initGlobalState(preSelectPackage: string) {
2525
await freshGlobalState(preSelectPackage);
2626
}
2727

28-
async function freshGlobalState(preSelectPackage: string) {
28+
export async function freshGlobalState(preSelectPackage: string) {
2929
const cliCurrentPath = (yargs.argv.cwd as string) || process.cwd();
3030
globalState.projectRootPath = cliCurrentPath;
3131

src/utils/ts-plus-babel.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ const buildTs = (watch: boolean, outdir: string, babelOptions: any, wholeProject
3636
};
3737

3838
const buildSass = (watch: boolean, outdir: string, wholeProject: boolean) => {
39-
const targetPath = wholeProject
40-
? path.join(pri.projectRootPath, '{src,packages}/**/*.scss')
41-
: path.join(pri.sourceRoot, srcPath.dir, '**/*.scss');
39+
const targetPath =
40+
wholeProject || (pri.selectedSourceType === 'root' && pri.sourceConfig.cssExtract)
41+
? path.join(pri.projectRootPath, '{src,packages}/**/*.scss')
42+
: path.join(pri.sourceRoot, srcPath.dir, '**/*.scss');
4243

4344
return new Promise((resolve, reject) => {
4445
getGulpByWatch(watch, targetPath)
@@ -52,9 +53,10 @@ const buildSass = (watch: boolean, outdir: string, wholeProject: boolean) => {
5253
};
5354

5455
const mvResources = (watch: boolean, outdir: string, wholeProject: boolean) => {
55-
const targetPath = wholeProject
56-
? path.join(pri.projectRootPath, '{src,packages}/**/*.{js,png,jpg,jpeg,gif,woff,woff2,eot,ttf,svg}')
57-
: path.join(pri.sourceRoot, srcPath.dir, '**/*.{js,png,jpg,jpeg,gif,woff,woff2,eot,ttf,svg}');
56+
const targetPath =
57+
wholeProject || (pri.selectedSourceType === 'root' && pri.sourceConfig.cssExtract)
58+
? path.join(pri.projectRootPath, '{src,packages}/**/*.{js,png,jpg,jpeg,gif,woff,woff2,eot,ttf,svg}')
59+
: path.join(pri.sourceRoot, srcPath.dir, '**/*.{js,png,jpg,jpeg,gif,woff,woff2,eot,ttf,svg}');
5860

5961
return new Promise((resolve, reject) => {
6062
getGulpByWatch(watch, targetPath)
@@ -96,12 +98,14 @@ function importRename(packageAbsoluteToRelative = false) {
9698
}
9799

98100
export const tsPlusBabel = async (watch = false, wholeProject = false) => {
99-
const mainDistPath = path.join(globalState.projectRootPath, pri.sourceConfig.distDir, 'main');
100-
const moduleDistPath = path.join(globalState.projectRootPath, pri.sourceConfig.distDir, 'module');
101+
const rootDistPath = path.join(globalState.projectRootPath, pri.sourceConfig.distDir);
102+
const mainDistPath = path.join(rootDistPath, 'main');
103+
const moduleDistPath = path.join(rootDistPath, 'module');
101104

102105
return Promise.all([
103106
buildSass(watch, mainDistPath, wholeProject),
104-
mvResources(watch, mainDistPath, wholeProject),
107+
buildSass(watch, moduleDistPath, wholeProject),
108+
105109
buildTs(
106110
watch,
107111
mainDistPath,
@@ -110,8 +114,6 @@ export const tsPlusBabel = async (watch = false, wholeProject = false) => {
110114
}),
111115
wholeProject,
112116
),
113-
buildSass(watch, moduleDistPath, wholeProject),
114-
mvResources(watch, moduleDistPath, wholeProject),
115117
buildTs(
116118
watch,
117119
moduleDistPath,
@@ -121,5 +123,8 @@ export const tsPlusBabel = async (watch = false, wholeProject = false) => {
121123
}),
122124
wholeProject,
123125
),
126+
127+
mvResources(watch, mainDistPath, wholeProject),
128+
mvResources(watch, moduleDistPath, wholeProject),
124129
]);
125130
};

0 commit comments

Comments
 (0)