Skip to content

Commit b854d7b

Browse files
authored
fix: bff package path (#6843)
1 parent 1191444 commit b854d7b

File tree

3 files changed

+279
-262
lines changed

3 files changed

+279
-262
lines changed

.changeset/thick-rules-lie.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@modern-js/plugin-bff': patch
3+
---
4+
5+
fix(bff): fixed path issue of generating package.json attribute
6+
fix(bff): 修复生成 package.json 属性的路径问题

packages/cli/plugin-bff/src/utils/clientGenerator.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ const CLIENT_DIR = 'client';
3333
const EXPORT_PREFIX = `./${API_DIR}/`;
3434
const TYPE_PREFIX = `${API_DIR}/`;
3535

36+
const toPosixPath = (p: string) => p.replace(/\\/g, '/');
37+
const posixJoin = (...args: string[]) => toPosixPath(path.join(...args));
38+
3639
export async function readDirectoryFiles(
3740
appDirectory: string,
3841
directory: string,
@@ -55,7 +58,7 @@ export async function readDirectoryFiles(
5558
const relativePath = path.relative(directory, resourcePath);
5659
const parsedPath = path.parse(relativePath);
5760

58-
const targetDir = path.join(
61+
const targetDir = posixJoin(
5962
`./${relativeDistPath}/${CLIENT_DIR}`,
6063
parsedPath.dir,
6164
`${parsedPath.name}.js`,
@@ -66,13 +69,13 @@ export async function readDirectoryFiles(
6669
appDirectory,
6770
currentPath,
6871
);
69-
const typesFilePath = path.join(
72+
const typesFilePath = posixJoin(
7073
`./${relativeDistPath}`,
7174
relativePathFromAppDirectory,
7275
`${name}.d.ts`,
7376
);
7477
const relativeTargetDistDir = `./${typesFilePath}`;
75-
const exportKey = path.join(parsedPath.dir, name);
78+
const exportKey = toPosixPath(path.join(parsedPath.dir, name));
7679

7780
filesList.push({
7881
resourcePath,
@@ -136,48 +139,55 @@ async function setPackage(
136139
const packageJson = JSON.parse(packageContent);
137140

138141
const addFiles = [
139-
`${relativeDistPath}/${CLIENT_DIR}/**/*`,
140-
`${relativeDistPath}/${RUNTIME_DIR}/**/*`,
141-
`${relativeDistPath}/${PLUGIN_DIR}/**/*`,
142+
posixJoin(relativeDistPath, CLIENT_DIR, '**', '*'),
143+
posixJoin(relativeDistPath, RUNTIME_DIR, '**', '*'),
144+
posixJoin(relativeDistPath, PLUGIN_DIR, '**', '*'),
142145
];
143146

144147
const typesVersions = {
145148
'*': files.reduce(
146149
(acc, file) => {
147-
const typeFilePath = `./${file.targetDir}`.replace('js', 'd.ts');
150+
const typeFilePath = toPosixPath(`./${file.targetDir}`).replace(
151+
'js',
152+
'd.ts',
153+
);
148154
return {
149155
...acc,
150-
[`${TYPE_PREFIX}${file.exportKey}`]: [typeFilePath],
156+
[toPosixPath(`${TYPE_PREFIX}${file.exportKey}`)]: [typeFilePath],
151157
};
152158
},
153159
{
154-
[RUNTIME_DIR]: [`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`],
155-
[PLUGIN_DIR]: [`./${relativeDistPath}/${PLUGIN_DIR}/index.d.ts`],
160+
[RUNTIME_DIR]: [
161+
toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`),
162+
],
163+
[PLUGIN_DIR]: [
164+
toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.d.ts`),
165+
],
156166
},
157167
),
158168
};
159169

160170
const exports = files.reduce(
161171
(acc, file) => {
162172
const exportKey = `${EXPORT_PREFIX}${file.exportKey}`;
163-
const jsFilePath = `./${file.targetDir}`;
173+
const jsFilePath = toPosixPath(`./${file.targetDir}`);
164174

165175
return {
166176
...acc,
167-
[exportKey]: {
177+
[toPosixPath(exportKey)]: {
168178
import: jsFilePath,
169-
types: jsFilePath.replace(/\.js$/, '.d.ts'),
179+
types: toPosixPath(jsFilePath.replace(/\.js$/, '.d.ts')),
170180
},
171181
};
172182
},
173183
{
174-
[`./${PLUGIN_DIR}`]: {
175-
require: `./${relativeDistPath}/${PLUGIN_DIR}/index.js`,
176-
types: `./${relativeDistPath}/${PLUGIN_DIR}/index.d.ts`,
184+
[toPosixPath(`./${PLUGIN_DIR}`)]: {
185+
require: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.js`),
186+
types: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.d.ts`),
177187
},
178-
[`./${RUNTIME_DIR}`]: {
179-
import: `./${relativeDistPath}/${RUNTIME_DIR}/index.js`,
180-
types: `./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`,
188+
[toPosixPath(`./${RUNTIME_DIR}`)]: {
189+
import: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.js`),
190+
types: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`),
181191
},
182192
},
183193
);
@@ -195,7 +205,7 @@ async function setPackage(
195205

196206
export async function copyFiles(from: string, to: string) {
197207
if (await fs.pathExists(from)) {
198-
await fs.copy(from, to);
208+
await fs.copy(toPosixPath(from), toPosixPath(to));
199209
}
200210
}
201211

0 commit comments

Comments
 (0)