Skip to content

Commit 379d9aa

Browse files
committed
Fix build error when source or target path occurs 1+ times in path
Closes CommunitySolidServer/CommunitySolidServer#511
1 parent 972bb31 commit 379d9aa

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

bin/componentsjs-generator.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22
import * as fs from 'fs';
3+
import * as Path from 'path';
34
import * as minimist from 'minimist';
45
import { Generator } from '../lib/generate/Generator';
56
import { ResolutionContext } from '../lib/resolution/ResolutionContext';
@@ -24,12 +25,13 @@ const args = minimist(process.argv.slice(2));
2425
if (args.help) {
2526
showHelp();
2627
} else {
28+
const packageRootDirectory = Path.posix.join(process.cwd(), args.p || '');
2729
const generator = new Generator({
2830
resolutionContext: new ResolutionContext(),
2931
pathDestination: {
30-
packageRootDirectory: args.p || process.cwd(),
31-
originalPath: args.s || 'lib',
32-
replacementPath: args.c || 'components',
32+
packageRootDirectory,
33+
originalPath: Path.posix.join(packageRootDirectory, args.s || 'lib'),
34+
replacementPath: Path.posix.join(packageRootDirectory, args.c || 'components'),
3335
},
3436
fileExtension: args.e || 'jsonld',
3537
logLevel: args.l || 'info',

lib/serialize/ComponentConstructor.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,17 @@ export interface ComponentConstructorArgs {
497497
}
498498

499499
export interface PathDestinationDefinition {
500+
/**
501+
* Absolute path to the package root.
502+
*/
500503
packageRootDirectory: string;
504+
/**
505+
* Absolute path to the package source directory.
506+
*/
501507
originalPath: string;
508+
/**
509+
* Absolute path to the package components target directory.
510+
*/
502511
replacementPath: string;
503512
}
504513

lib/serialize/ComponentSerializer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export class ComponentSerializer {
5151
*/
5252
public async serializeComponentsIndex(componentsIndex: ComponentDefinitionsIndex): Promise<string> {
5353
const filePathBase = Path.join(
54-
this.pathDestination.packageRootDirectory,
5554
this.pathDestination.replacementPath,
5655
'components',
5756
);
@@ -65,7 +64,6 @@ export class ComponentSerializer {
6564
*/
6665
public async serializeContext(contextRaw: ContextRaw): Promise<string> {
6766
const filePathBase = Path.join(
68-
this.pathDestination.packageRootDirectory,
6967
this.pathDestination.replacementPath,
7068
'context',
7169
);

test/serialize/ComponentSerialize.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ describe('ComponentSerializer', () => {
1212
resolutionContext,
1313
pathDestination: {
1414
packageRootDirectory: '/',
15-
originalPath: 'src',
16-
replacementPath: 'components',
15+
originalPath: '/src',
16+
replacementPath: '/components',
1717
},
1818
fileExtension: 'jsonld',
1919
indentation: ' ',

0 commit comments

Comments
 (0)