|
| 1 | +/* |
| 2 | + Copyright 2025 Google LLC |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { readFileSync, writeFileSync } from 'fs'; |
| 18 | +import { join } from 'path'; |
| 19 | + |
| 20 | +// Locally we depend on the Lit package via a relative path so we can test it from source. |
| 21 | +// This breaks when published to npm so the following script updates the version to the npm one. |
| 22 | + |
| 23 | +const dirname = import.meta.dirname; |
| 24 | +const litVersion = parsePackageJson(join(dirname, '../lit/package.json')).version; |
| 25 | + |
| 26 | +if (!litVersion) { |
| 27 | + throw new Error('Cannot determine version of Lit package'); |
| 28 | +} |
| 29 | + |
| 30 | +const packageJsonPath = join(dirname, './dist/package.json'); |
| 31 | +const packageJson = parsePackageJson(packageJsonPath); |
| 32 | + |
| 33 | +if (!packageJson.dependencies['@a2ui/lit']) { |
| 34 | + throw new Error( |
| 35 | + 'Angular package does not depend on the Lit library. ' + |
| 36 | + 'Either update the package.json or remove this script.', |
| 37 | + ); |
| 38 | +} |
| 39 | + |
| 40 | +packageJson.dependencies['@a2ui/lit'] = '^' + litVersion; |
| 41 | +writeFileSync(packageJsonPath, JSON.stringify(packageJson, undefined, 2)); |
| 42 | + |
| 43 | +function parsePackageJson(path) { |
| 44 | + const content = readFileSync(path, 'utf8'); |
| 45 | + return JSON.parse(content); |
| 46 | +} |
0 commit comments