|
1 | 1 | import * as Path from 'path'; |
2 | | -import { ModuleStateBuilder } from 'componentsjs/lib/loading/ModuleStateBuilder'; |
| 2 | +import semverMajor = require('semver/functions/major'); |
3 | 3 | import type { ResolutionContext } from '../resolution/ResolutionContext'; |
4 | 4 |
|
5 | 5 | /** |
@@ -27,13 +27,19 @@ export class PackageMetadataLoader { |
27 | 27 | throw new Error(`Invalid package: Syntax error in ${packageJsonPath}: ${(<Error> error).message}`); |
28 | 28 | } |
29 | 29 |
|
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}`; |
34 | 33 | 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 | + }; |
37 | 43 | } |
38 | 44 |
|
39 | 45 | // Extract required fields from package.json |
|
0 commit comments