Skip to content

Commit f7c62a0

Browse files
committed
declare dependencies as peers & add version check
1 parent c1ba730 commit f7c62a0

File tree

47 files changed

+73
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+73
-36
lines changed

build/plugins/esbuild-plugin-umd.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ export function umdPlugin({ pkg, externals }) {
2525
}
2626

2727
function wrapUmd(fileContent, pkg, externals) {
28-
const deps = Object.keys(pkg.dependencies);
29-
if (!deps.includes('three')) {
30-
deps.unshift('three');
31-
}
28+
const deps = Object.keys(pkg.peerDependencies || {});
29+
deps.unshift('three');
3230

3331
const depsCommonJs = deps.map((dep) => `require('${dep}')`).join(', ');
3432
const depsAmd = deps.map((dep) => `'${dep}'`).join(', ');
@@ -52,6 +50,7 @@ ${fileContent
5250
.replace(`var ${globalParent};\n`, '')
5351
.replace(`var ${globalParent} = (() => {\n`, '')
5452
.replace(`(${globalParent} ||= {}).${globalName.split('.').pop()} = (() => {\n`, '')
53+
5554
// hydrate exports
5655
.replace(/return __toCommonJS\((.*?)\);\n}\)\(\);/, '__copyProps(__defProp(exports, "__esModule", { value: true }), $1);')
5756
// unused function
@@ -75,6 +74,7 @@ ${fileContent
7574
.replace(/ var __commonJS = ([\s\S]*?)};\n/, '')
7675
.replace(/ var __create = (.*?);\n/, '')
7776
.replace(/ var __getProtoOf = (.*?);\n/, '')
77+
7878
// remove plugin reference
7979
.replace(/external-global-plugin:/g, '')}
8080
}));`;

build/tsup.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ ${
4646
external: Object.keys(externals),
4747
noExternal: [/three\/examples\/.*/],
4848
target: 'es2021',
49+
define: {
50+
PKG_VERSION: `'${pkg.version}'`,
51+
},
4952
esbuildPlugins: [
5053
sassPlugin(),
5154
externalGlobalPlugin(externals),

packages/autorotate-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "MIT",
77
"main": "./src/index.ts",
88
"types": "./src/index.ts",
9-
"dependencies": {
9+
"peerDependencies": {
1010
"@photo-sphere-viewer/core": "0.0.0"
1111
},
1212
"scripts": {

packages/autorotate-plugin/src/AutorotatePlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class AutorotatePlugin extends AbstractConfigurablePlugin<
7272
AutorotatePluginEvents
7373
> {
7474
static override readonly id = 'autorotate';
75+
static override readonly VERSION = PKG_VERSION;
7576
static override readonly configParser = getConfig;
7677
static override readonly readonlyOptions: Array<keyof AutorotatePluginConfig> = ['keypoints'];
7778

packages/compass-plugin/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
"license": "MIT",
77
"main": "./src/index.ts",
88
"types": "./src/index.ts",
9-
"dependencies": {
9+
"peerDependencies": {
1010
"@photo-sphere-viewer/core": "0.0.0"
1111
},
12-
"optionalDependencies": {
13-
"@photo-sphere-viewer/markers-plugin": "0.0.0"
14-
},
1512
"scripts": {
1613
"build": "tsup",
1714
"watch": "tsup --watch",

packages/compass-plugin/src/CompassPlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class CompassPlugin extends AbstractConfigurablePlugin<
3333
UpdatableCompassPluginConfig
3434
> {
3535
static override readonly id = 'compass';
36+
static override readonly VERSION = PKG_VERSION;
3637
static override readonly configParser = getConfig;
3738
static override readonly readonlyOptions: Array<keyof CompassPluginConfig> = ['navigation'];
3839

packages/core/src/adapters/AbstractAdapter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Mesh, ShaderMaterial, ShaderMaterialParameters } from 'three';
22
import { PanoData, PanoDataProvider, PanoramaPosition, Position, TextureData } from '../model';
33
import type { Viewer } from '../Viewer';
44
import { PSVError } from '../PSVError';
5+
import { checkVersion } from '../utils';
56

67
/**
78
* Base class for adapters
@@ -14,6 +15,11 @@ export abstract class AbstractAdapter<TPanorama, TTexture, TData> {
1415
* Unique identifier of the adapter
1516
*/
1617
static readonly id: string;
18+
/**
19+
* Expected version of the core
20+
* DO NOT USE on custom adapters
21+
*/
22+
static readonly VERSION: string;
1723

1824
/**
1925
* Indicates if the adapter supports panorama download natively
@@ -186,6 +192,7 @@ export function adapterInterop(adapter: any): AdapterConstructor & typeof Abstra
186192
if (adapter) {
187193
for (const [, p] of [['_', adapter], ...Object.entries(adapter)]) {
188194
if (p.prototype instanceof AbstractAdapter) {
195+
checkVersion(p.id, p.VERSION, PKG_VERSION);
189196
return p;
190197
}
191198
}

packages/core/src/adapters/EquirectangularAdapter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const getConfig = getConfigParser<EquirectangularAdapterConfig>(
6464
*/
6565
export class EquirectangularAdapter extends AbstractAdapter<string, Texture, PanoData> {
6666
static override readonly id: string = 'equirectangular';
67+
static override readonly VERSION = PKG_VERSION;
6768
static override readonly supportsDownload: boolean = true;
6869
static override readonly supportsOverlay: boolean = true;
6970

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export { PSVError } from './PSVError';
3636
export { Viewer } from './Viewer';
3737
export * from './model';
3838
export { CONSTANTS, events, utils };
39+
export const VERSION = PKG_VERSION;
3940

4041
/** @internal */
4142
import './styles/index.scss';

packages/core/src/plugins/AbstractPlugin.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TypedEvent, TypedEventTarget } from '../lib/TypedEventTarget';
2-
import { ConfigParser, logWarn } from '../utils';
2+
import { checkVersion, ConfigParser, logWarn } from '../utils';
33
import type { Viewer } from '../Viewer';
44

55
/**
@@ -13,6 +13,11 @@ export abstract class AbstractPlugin<
1313
* Unique identifier of the plugin
1414
*/
1515
static readonly id: string;
16+
/**
17+
* Expected version of the core
18+
* DO NOT USE on custom plugins
19+
*/
20+
static readonly VERSION: string;
1621

1722
constructor(protected viewer: Viewer) {
1823
super();
@@ -112,6 +117,7 @@ export function pluginInterop(plugin: any): PluginConstructor & typeof AbstractP
112117
if (plugin) {
113118
for (const [, p] of [['_', plugin], ...Object.entries(plugin)]) {
114119
if (p.prototype instanceof AbstractPlugin) {
120+
checkVersion(p.id, p.VERSION, PKG_VERSION);
115121
return p;
116122
}
117123
}

0 commit comments

Comments
 (0)