@blastlauncher/shared-deps 0.0.0-stage → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +4 -2
- package/dist/index.d.ts +8 -0
- package/dist/index.js +135 -0
- package/package.json +43 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2023 Yukai Huang
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @blastlauncher/shared-deps
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Blast's shared-deps package.
|
|
4
|
+
Emitted ESM and TypeScript declarations for Node.js 24.20+.
|
|
5
|
+
See https://github.com/BlastLauncher/blast for documentation.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const PROVIDED_PACKAGES: readonly ["@raycast/api", "react", "@raycast/utils", "node-fetch", "axios", "date-fns", "lodash", "zod", "cheerio", "dayjs", "fuse.js", "uuid", "nanoid", "cross-fetch", "moment", "node-html-markdown"];
|
|
2
|
+
export declare function isProvidedSpecifier(specifier: string): boolean;
|
|
3
|
+
/** Whether a declared range admits a stable release of the provided line. */
|
|
4
|
+
export declare function isDependencyCompatible(name: string, range: unknown): boolean;
|
|
5
|
+
/** Warn only when no version in the supplied major can satisfy the declaration. */
|
|
6
|
+
export declare function dependencyWarnings(declarations?: Record<string, unknown>): string[];
|
|
7
|
+
/** Resolve from this package, never from the extension or engine install. */
|
|
8
|
+
export declare function resolveShared(specifier: string, kind?: "import" | "require"): string | undefined;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { isAbsolute, join } from "node:path";
|
|
4
|
+
import { Range, parse, validRange } from "semver";
|
|
5
|
+
import manifest from "../package.json" with { type: "json" };
|
|
6
|
+
// Interim, ranked by corpus imports. No native addons, install hooks or binaries.
|
|
7
|
+
// Size and platform exclusions are recorded in decision 0002.
|
|
8
|
+
export const PROVIDED_PACKAGES = [
|
|
9
|
+
"@raycast/api",
|
|
10
|
+
"react",
|
|
11
|
+
"@raycast/utils",
|
|
12
|
+
"node-fetch",
|
|
13
|
+
"axios",
|
|
14
|
+
"date-fns",
|
|
15
|
+
"lodash",
|
|
16
|
+
"zod",
|
|
17
|
+
"cheerio",
|
|
18
|
+
"dayjs",
|
|
19
|
+
"fuse.js",
|
|
20
|
+
"uuid",
|
|
21
|
+
"nanoid",
|
|
22
|
+
"cross-fetch",
|
|
23
|
+
"moment",
|
|
24
|
+
"node-html-markdown",
|
|
25
|
+
];
|
|
26
|
+
export function isProvidedSpecifier(specifier) {
|
|
27
|
+
return PROVIDED_PACKAGES.some((name) => specifier === name || specifier.startsWith(`${name}/`));
|
|
28
|
+
}
|
|
29
|
+
/** Resolve the semver part of a dependency declaration, if it has one. */
|
|
30
|
+
function normalizedRange(name, value) {
|
|
31
|
+
if (typeof value !== "string")
|
|
32
|
+
return undefined;
|
|
33
|
+
const raw = value.trim();
|
|
34
|
+
if (raw === "latest" || raw === "*")
|
|
35
|
+
return { range: "*", wildcard: true };
|
|
36
|
+
if (raw.startsWith("npm:")) {
|
|
37
|
+
const alias = /^npm:(@[^/]+\/[^@]+|[^@]+)(?:@(.+))?$/.exec(raw);
|
|
38
|
+
if (!alias || alias[1] !== name)
|
|
39
|
+
return undefined;
|
|
40
|
+
const inner = alias[2]?.trim() || "*";
|
|
41
|
+
return validRange(inner) ? { range: inner, wildcard: inner === "*" } : undefined;
|
|
42
|
+
}
|
|
43
|
+
return validRange(raw) ? { range: raw, wildcard: false } : undefined;
|
|
44
|
+
}
|
|
45
|
+
function stableVersionCandidates(version, set) {
|
|
46
|
+
const candidates = new Set([`${version.major}.0.0`, version.version]);
|
|
47
|
+
for (const comparator of set) {
|
|
48
|
+
const value = comparator.semver;
|
|
49
|
+
if (!value || value.major !== version.major)
|
|
50
|
+
continue;
|
|
51
|
+
const { minor, patch } = value;
|
|
52
|
+
candidates.add(`${value.major}.${minor}.${patch}`);
|
|
53
|
+
candidates.add(`${value.major}.${minor}.${patch + 1}`);
|
|
54
|
+
candidates.add(`${value.major}.${minor + 1}.0`);
|
|
55
|
+
if (patch > 0)
|
|
56
|
+
candidates.add(`${value.major}.${minor}.${patch - 1}`);
|
|
57
|
+
if (minor > 0)
|
|
58
|
+
candidates.add(`${value.major}.${minor - 1}.0`);
|
|
59
|
+
}
|
|
60
|
+
return [...candidates];
|
|
61
|
+
}
|
|
62
|
+
/** Whether one comparator set admits a stable version on the provided line. */
|
|
63
|
+
function admitsStableVersion(version, set) {
|
|
64
|
+
const line = version.major === 0 ? `${version.major}.${version.minor}` : `${version.major}`;
|
|
65
|
+
const hasStableComparator = set.some((comparator) => comparator.value === "" || comparator.semver?.prerelease.length === 0);
|
|
66
|
+
if (!hasStableComparator)
|
|
67
|
+
return false;
|
|
68
|
+
return stableVersionCandidates(version, set).some((candidate) => {
|
|
69
|
+
const parsed = parse(candidate);
|
|
70
|
+
return (parsed !== null &&
|
|
71
|
+
(version.major === 0
|
|
72
|
+
? `${parsed.major}.${parsed.minor}` === line
|
|
73
|
+
: parsed.major === version.major) &&
|
|
74
|
+
parsed.prerelease.length === 0 &&
|
|
75
|
+
set.every((comparator) => comparator.test(parsed)));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** Whether a declared range admits a stable release of the provided line. */
|
|
79
|
+
export function isDependencyCompatible(name, range) {
|
|
80
|
+
const pinned = manifest.dependencies[name];
|
|
81
|
+
if (!pinned)
|
|
82
|
+
return true;
|
|
83
|
+
const version = parse(pinned);
|
|
84
|
+
const normalized = normalizedRange(name, range);
|
|
85
|
+
if (!version || !normalized)
|
|
86
|
+
return false;
|
|
87
|
+
if (normalized.wildcard)
|
|
88
|
+
return true;
|
|
89
|
+
let parsed;
|
|
90
|
+
try {
|
|
91
|
+
parsed = new Range(normalized.range);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return parsed.set.some((set) => admitsStableVersion(version, set));
|
|
97
|
+
}
|
|
98
|
+
/** Warn only when no version in the supplied major can satisfy the declaration. */
|
|
99
|
+
export function dependencyWarnings(declarations = {}) {
|
|
100
|
+
const pinned = manifest.dependencies;
|
|
101
|
+
return PROVIDED_PACKAGES.flatMap((name) => {
|
|
102
|
+
const version = pinned[name];
|
|
103
|
+
const range = declarations[name];
|
|
104
|
+
if (!version || !normalizedRange(name, range))
|
|
105
|
+
return [];
|
|
106
|
+
if (isDependencyCompatible(name, range))
|
|
107
|
+
return [];
|
|
108
|
+
return [`Shared dependency ${name}: declared ${range}, provided ${version} (major mismatch)`];
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const requireShared = createRequire(import.meta.url);
|
|
112
|
+
/** Resolve from this package, never from the extension or engine install. */
|
|
113
|
+
export function resolveShared(specifier, kind = "import") {
|
|
114
|
+
if (!isProvidedSpecifier(specifier) ||
|
|
115
|
+
specifier === "@raycast/api" ||
|
|
116
|
+
/^react(?:\/|$)/.test(specifier))
|
|
117
|
+
return undefined;
|
|
118
|
+
const resolved = kind === "require" ? requireShared.resolve(specifier) : import.meta.resolve(specifier);
|
|
119
|
+
if (resolved.startsWith("file:"))
|
|
120
|
+
return fileURLToPath(resolved);
|
|
121
|
+
if (isAbsolute(resolved))
|
|
122
|
+
return resolved;
|
|
123
|
+
// Bun aliases npm names (e.g. node-fetch) to built-ins. Absolute lookup
|
|
124
|
+
// bypasses those aliases while retaining this package's search paths.
|
|
125
|
+
for (const directory of requireShared.resolve.paths(`${specifier}/package.json`) ?? []) {
|
|
126
|
+
try {
|
|
127
|
+
return requireShared.resolve(join(directory, specifier));
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
if (error.code !== "MODULE_NOT_FOUND")
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
throw new Error(`Cannot resolve shared dependency ${specifier}`);
|
|
135
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blastlauncher/shared-deps",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
"type": "module",
|
|
4
|
+
"exports": {
|
|
5
|
+
".": {
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"import": "./dist/index.js",
|
|
8
|
+
"default": "./dist/index.js"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@raycast/utils": "2.3.2",
|
|
13
|
+
"axios": "1.20.0",
|
|
14
|
+
"cheerio": "1.2.0",
|
|
15
|
+
"cross-fetch": "4.1.0",
|
|
16
|
+
"date-fns": "4.4.0",
|
|
17
|
+
"dayjs": "1.11.23",
|
|
18
|
+
"fuse.js": "7.5.0",
|
|
19
|
+
"lodash": "4.18.1",
|
|
20
|
+
"moment": "2.31.0",
|
|
21
|
+
"nanoid": "5.1.16",
|
|
22
|
+
"node-fetch": "3.3.2",
|
|
23
|
+
"node-html-markdown": "1.3.0",
|
|
24
|
+
"semver": "7.8.5",
|
|
25
|
+
"uuid": "11.1.1",
|
|
26
|
+
"zod": "4.6.7"
|
|
27
|
+
},
|
|
28
|
+
"version": "3.0.0-alpha.1",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/BlastLauncher/blast.git",
|
|
33
|
+
"directory": "packages/shared-deps"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/BlastLauncher/blast#readme",
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=24.20.0"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"schema",
|
|
42
|
+
"LICENSE",
|
|
43
|
+
"README.md"
|
|
44
|
+
]
|
|
45
|
+
}
|