Skip to content

Commit d92f477

Browse files
committed
Ignore existing files when expanding lsd:module: true
1 parent 9e674d2 commit d92f477

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

lib/parse/PackageMetadataLoader.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Path from 'path';
2-
import { ModuleStateBuilder } from 'componentsjs/lib/loading/ModuleStateBuilder';
2+
import semverMajor = require('semver/functions/major');
33
import type { ResolutionContext } from '../resolution/ResolutionContext';
44

55
/**
@@ -27,13 +27,19 @@ export class PackageMetadataLoader {
2727
throw new Error(`Invalid package: Syntax error in ${packageJsonPath}: ${(<Error> error).message}`);
2828
}
2929

30-
// Preprocess to expand things like `"lsd:module": true`
31-
if (await ModuleStateBuilder.preprocessPackageJson(packageRootDirectory, packageJson)) {
32-
// Add default imports paths, which will not be autogenerated, as they do not exist yet
33-
const baseUrl = Object.keys(packageJson['lsd:contexts'])[0].replace('components/context.jsonld', '');
30+
// Preprocess to expand `"lsd:module": true`
31+
if (packageJson['lsd:module'] === true) {
32+
packageJson['lsd:module'] = `https://linkedsoftwaredependencies.org/bundles/npm/${packageJson.name}`;
3433
const basePath = packageJson['lsd:basePath'] || '';
35-
packageJson['lsd:importPaths'][`${baseUrl}components/`] = `${basePath}components/`;
36-
packageJson['lsd:importPaths'][`${baseUrl}config/`] = `${basePath}config/`;
34+
packageJson['lsd:components'] = `${basePath}components/components.jsonld`;
35+
const baseIri = `${packageJson['lsd:module']}/^${semverMajor(packageJson.version)}.0.0/`;
36+
packageJson['lsd:contexts'] = {
37+
[`${baseIri}components/context.jsonld`]: `${basePath}components/context.jsonld`,
38+
};
39+
packageJson['lsd:importPaths'] = {
40+
[`${baseIri}components/`]: `${basePath}components/`,
41+
[`${baseIri}config/`]: `${basePath}config/`,
42+
};
3743
}
3844

3945
// Extract required fields from package.json

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@
7171
],
7272
"dependencies": {
7373
"@types/lru-cache": "^5.1.0",
74+
"@types/semver": "^7.3.4",
7475
"@typescript-eslint/typescript-estree": "^4.6.1",
7576
"comment-parser": "^0.7.6",
7677
"jsonld-context-parser": "^2.0.2",
7778
"lru-cache": "^6.0.0",
78-
"minimist": "^1.2.5"
79+
"minimist": "^1.2.5",
80+
"semver": "^7.3.2"
7981
},
8082
"devDependencies": {
8183
"@rubensworks/eslint-config": "^1.0.1",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,11 @@
812812
"@types/glob" "*"
813813
"@types/node" "*"
814814

815+
"@types/semver@^7.3.4":
816+
version "7.3.4"
817+
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.4.tgz#43d7168fec6fa0988bb1a513a697b29296721afb"
818+
integrity sha512-+nVsLKlcUCeMzD2ufHEYuJ9a2ovstb6Dp52A5VsoKxDXgvE051XgHI/33I1EymwkRGQkwnA0LkhnUzituGs4EQ==
819+
815820
"@types/stack-utils@^1.0.1":
816821
version "1.0.1"
817822
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"

0 commit comments

Comments
 (0)