@bubblydoo/uxp-toolkit 0.0.7 → 0.0.9
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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +12 -0
- package/dist/{chunk-3CLJMC63.js → chunk-JBXCIUBZ.js} +49 -90
- package/dist/commands-library/index.d.ts +38 -39
- package/dist/commands-library/index.js +171 -171
- package/dist/index.d.ts +39 -41
- package/dist/index.js +189 -150
- package/dist/{psLayerRef-OY3h7srv.d.ts → psLayerRef-CGbTO4a5.d.ts} +36 -37
- package/package.json +8 -7
- package/src/commands-library/addLayerToSelection.ts +4 -4
- package/src/commands-library/applyLayerMask.ts +2 -2
- package/src/commands-library/convertMode.ts +2 -2
- package/src/commands-library/createColorLookupAdjustmentLayer.ts +2 -2
- package/src/commands-library/expandFolder.ts +4 -4
- package/src/commands-library/exportLUTs.ts +4 -4
- package/src/commands-library/getDocument.ts +7 -7
- package/src/commands-library/getLayer.ts +13 -13
- package/src/commands-library/hasVectorMask.ts +2 -2
- package/src/commands-library/index.ts +18 -18
- package/src/commands-library/loadLayerMaskAsSelection.ts +2 -2
- package/src/commands-library/multiGetDocument.ts +14 -14
- package/src/commands-library/rasterizeLayerStyle.ts +3 -3
- package/src/commands-library/rasterizeVectorMask.ts +2 -2
- package/src/commands-library/removeLayerMask.ts +2 -2
- package/src/commands-library/renameLayer.ts +6 -6
- package/src/commands-library/renameLayer.uxp-test.ts +13 -13
- package/src/commands-library/renderGrid.ts +2 -2
- package/src/commands-library/selectLayer.ts +3 -3
- package/src/commands-library/set3DLUTColorLookup.ts +2 -2
- package/src/core/batchPlay.ts +3 -3
- package/src/core/command.test-d.ts +11 -8
- package/src/core/command.ts +20 -23
- package/src/core/executeAsModal.ts +13 -11
- package/src/core/suspendHistory.ts +3 -3
- package/src/core/suspendHistory.uxp-test.ts +8 -8
- package/src/core-wrappers/executeAsModalAndSuspendHistory.ts +8 -6
- package/src/dom/getFlattenedDomLayersList.ts +6 -7
- package/src/dom/photoshopDomLayersToTree.ts +5 -5
- package/src/error-sourcemaps/sourcemaps.ts +23 -21
- package/src/error-sourcemaps/sourcemaps.uxp-test.ts +9 -8
- package/src/errors/ut-error.ts +2 -2
- package/src/filesystem/openFileByPath.ts +4 -4
- package/src/general-tree/flattenTree.ts +1 -1
- package/src/general-tree/layerRef.ts +2 -2
- package/src/general-tree/mapTree.ts +1 -1
- package/src/general-tree/mapTreeRef.ts +1 -1
- package/src/general-tree/treeTypes.ts +0 -2
- package/src/index.ts +43 -43
- package/src/metadata-storage/metadataStorage.ts +31 -31
- package/src/metadata-storage/metadataStorage.uxp-test.ts +11 -11
- package/src/node-compat/path/resolvePath.ts +6 -4
- package/src/other/applicationInfo.ts +11 -11
- package/src/other/applicationInfo.uxp-test.ts +6 -6
- package/src/other/clipboard.ts +2 -2
- package/src/other/clipboard.uxp-test.ts +9 -8
- package/src/other/uxpEntrypoints.ts +2 -2
- package/src/ut-tree/getDocumentLayerDescriptors.ts +6 -6
- package/src/ut-tree/getLayerEffects.ts +5 -5
- package/src/ut-tree/hasBackgroundLayer.uxp-test.ts +25 -23
- package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.test.ts +29 -29
- package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.ts +62 -62
- package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.uxp-test.ts +29 -29
- package/src/ut-tree/psLayerRef.ts +2 -2
- package/src/ut-tree/utLayersToText.test.ts +32 -32
- package/src/ut-tree/utLayersToText.ts +19 -19
- package/src/ut-tree/utLayersToTree.ts +4 -4
- package/src/util/utLayerPickKeysType.ts +3 -3
- package/src/util/utLayerToLayer.ts +14 -13
- package/test/index.ts +11 -11
- package/test/meta-tests/builtinModules.uxp-test.ts +28 -26
- package/test/meta-tests/executeAsModal.uxp-test.ts +14 -12
- package/test/meta-tests/suspendHistory.uxp-test.ts +10 -9
- package/tsconfig.json +5 -5
- package/tsup.config.ts +5 -5
- package/uxp-tests.json +1 -1
- package/vitest-photoshop-alias-plugin.ts +23 -21
- package/vitest.config.ts +6 -6
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { expect, it } from
|
|
2
|
-
import { utLayersToText } from
|
|
1
|
+
import { expect, it } from 'vitest';
|
|
2
|
+
import { utLayersToText } from './utLayersToText';
|
|
3
3
|
|
|
4
|
-
it(
|
|
4
|
+
it('converts a single layer to text', () => {
|
|
5
5
|
expect(utLayersToText([
|
|
6
6
|
{
|
|
7
|
-
name:
|
|
7
|
+
name: 'circle',
|
|
8
8
|
effects: {},
|
|
9
|
-
blendMode:
|
|
9
|
+
blendMode: 'normal',
|
|
10
10
|
isClippingMask: false,
|
|
11
|
-
kind:
|
|
11
|
+
kind: 'pixel',
|
|
12
12
|
visible: true,
|
|
13
13
|
},
|
|
14
|
-
])).toMatchInlineSnapshot(`"◯ circle"`)
|
|
14
|
+
])).toMatchInlineSnapshot(`"◯ circle"`);
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
it(
|
|
17
|
+
it('converts a nested layer to text', () => {
|
|
18
18
|
expect(utLayersToText([
|
|
19
19
|
{
|
|
20
|
-
name:
|
|
20
|
+
name: 'group',
|
|
21
21
|
effects: {},
|
|
22
|
-
blendMode:
|
|
22
|
+
blendMode: 'passThrough',
|
|
23
23
|
isClippingMask: false,
|
|
24
|
-
kind:
|
|
24
|
+
kind: 'group',
|
|
25
25
|
visible: true,
|
|
26
26
|
layers: [
|
|
27
27
|
{
|
|
28
|
-
name:
|
|
28
|
+
name: 'circle',
|
|
29
29
|
effects: {},
|
|
30
|
-
blendMode:
|
|
30
|
+
blendMode: 'normal',
|
|
31
31
|
isClippingMask: false,
|
|
32
|
-
kind:
|
|
32
|
+
kind: 'pixel',
|
|
33
33
|
visible: true,
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
|
-
name:
|
|
36
|
+
name: 'square',
|
|
37
37
|
effects: {},
|
|
38
|
-
blendMode:
|
|
38
|
+
blendMode: 'normal',
|
|
39
39
|
isClippingMask: false,
|
|
40
|
-
kind:
|
|
40
|
+
kind: 'pixel',
|
|
41
41
|
visible: true,
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
|
-
name:
|
|
44
|
+
name: 'other',
|
|
45
45
|
effects: {},
|
|
46
|
-
blendMode:
|
|
46
|
+
blendMode: 'passThrough',
|
|
47
47
|
isClippingMask: false,
|
|
48
|
-
kind:
|
|
48
|
+
kind: 'group',
|
|
49
49
|
visible: true,
|
|
50
50
|
layers: [
|
|
51
51
|
{
|
|
52
|
-
name:
|
|
52
|
+
name: 'nested',
|
|
53
53
|
effects: {},
|
|
54
|
-
blendMode:
|
|
54
|
+
blendMode: 'normal',
|
|
55
55
|
isClippingMask: false,
|
|
56
|
-
kind:
|
|
56
|
+
kind: 'pixel',
|
|
57
57
|
visible: true,
|
|
58
58
|
},
|
|
59
59
|
],
|
|
@@ -66,29 +66,29 @@ it("converts a nested layer to text", () => {
|
|
|
66
66
|
◯ square
|
|
67
67
|
◯ ▾ other
|
|
68
68
|
◯ nested"
|
|
69
|
-
`)
|
|
69
|
+
`);
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
it(
|
|
72
|
+
it('converts a nested layer with a clipping mask to text', () => {
|
|
73
73
|
expect(utLayersToText([
|
|
74
74
|
{
|
|
75
|
-
name:
|
|
75
|
+
name: 'clipper',
|
|
76
76
|
effects: {},
|
|
77
|
-
blendMode:
|
|
77
|
+
blendMode: 'normal',
|
|
78
78
|
isClippingMask: true,
|
|
79
|
-
kind:
|
|
79
|
+
kind: 'pixel',
|
|
80
80
|
visible: true,
|
|
81
81
|
},
|
|
82
82
|
{
|
|
83
|
-
name:
|
|
83
|
+
name: 'circle',
|
|
84
84
|
effects: {},
|
|
85
|
-
blendMode:
|
|
85
|
+
blendMode: 'normal',
|
|
86
86
|
isClippingMask: false,
|
|
87
|
-
kind:
|
|
87
|
+
kind: 'pixel',
|
|
88
88
|
visible: true,
|
|
89
89
|
},
|
|
90
90
|
])).toMatchInlineSnapshot(`
|
|
91
91
|
"◯ ⬐ clipper
|
|
92
92
|
◯ circle"
|
|
93
|
-
`)
|
|
93
|
+
`);
|
|
94
94
|
});
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import type { UTLayerPickKeys } from
|
|
2
|
-
import type { UTLayer } from
|
|
1
|
+
import type { UTLayerPickKeys } from '../util/utLayerPickKeysType';
|
|
2
|
+
import type { UTLayer } from './photoshopLayerDescriptorsToUTLayers';
|
|
3
3
|
|
|
4
|
-
const VISIBLE_ICON =
|
|
5
|
-
const INVISIBLE_ICON =
|
|
6
|
-
const CLIPPING_MASK_ICON =
|
|
7
|
-
const GROUP_ICON =
|
|
8
|
-
const EFFECTS_ICON =
|
|
9
|
-
const BLEND_ICON =
|
|
4
|
+
const VISIBLE_ICON = '◯';
|
|
5
|
+
const INVISIBLE_ICON = '⊘';
|
|
6
|
+
const CLIPPING_MASK_ICON = '⬐';
|
|
7
|
+
const GROUP_ICON = '▾';
|
|
8
|
+
const EFFECTS_ICON = 'ƒ';
|
|
9
|
+
const BLEND_ICON = '⁕';
|
|
10
10
|
|
|
11
|
-
type MinimalUTLayer = UTLayerPickKeys<
|
|
11
|
+
type MinimalUTLayer = UTLayerPickKeys<'effects' | 'visible' | 'isClippingMask' | 'kind' | 'blendMode' | 'name'>;
|
|
12
12
|
|
|
13
13
|
export function utLayersToText(tree: MinimalUTLayer[], depth = 0): string {
|
|
14
14
|
return tree.map((layer) => {
|
|
15
|
-
const prefix =
|
|
15
|
+
const prefix = ' '.repeat(depth * 2);
|
|
16
16
|
const name = layer.name;
|
|
17
|
-
const effects = Object.keys(layer.effects).length > 0 ? EFFECTS_ICON :
|
|
18
|
-
const blend = isSpecialBlendMode(layer) ? BLEND_ICON :
|
|
19
|
-
const clippingMask = layer.isClippingMask ? CLIPPING_MASK_ICON :
|
|
20
|
-
const group = layer.kind ===
|
|
17
|
+
const effects = Object.keys(layer.effects).length > 0 ? EFFECTS_ICON : '';
|
|
18
|
+
const blend = isSpecialBlendMode(layer) ? BLEND_ICON : '';
|
|
19
|
+
const clippingMask = layer.isClippingMask ? CLIPPING_MASK_ICON : '';
|
|
20
|
+
const group = layer.kind === 'group' ? GROUP_ICON : '';
|
|
21
21
|
const visible = layer.visible ? VISIBLE_ICON : INVISIBLE_ICON;
|
|
22
|
-
const line = [visible, prefix, clippingMask, group, name, effects, blend].filter(Boolean).join(
|
|
22
|
+
const line = [visible, prefix, clippingMask, group, name, effects, blend].filter(Boolean).join(' ');
|
|
23
23
|
if (layer.layers) {
|
|
24
|
-
return line
|
|
24
|
+
return `${line}\n${utLayersToText(layer.layers, depth + 1)}`;
|
|
25
25
|
}
|
|
26
26
|
return line;
|
|
27
|
-
}).join(
|
|
27
|
+
}).join('\n');
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function isSpecialBlendMode(layer: Pick<UTLayer,
|
|
31
|
-
return layer.kind ===
|
|
30
|
+
function isSpecialBlendMode(layer: Pick<UTLayer, 'kind' | 'blendMode'>): boolean {
|
|
31
|
+
return layer.kind === 'group' ? layer.blendMode !== 'passThrough' : layer.blendMode !== 'normal';
|
|
32
32
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { Tree } from
|
|
2
|
-
import type { UTLayer } from
|
|
1
|
+
import type { Tree } from '../general-tree/treeTypes';
|
|
2
|
+
import type { UTLayer } from './photoshopLayerDescriptorsToUTLayers';
|
|
3
3
|
|
|
4
|
-
export type UTLayerWithoutChildren = Omit<UTLayer,
|
|
4
|
+
export type UTLayerWithoutChildren = Omit<UTLayer, 'layers'>;
|
|
5
5
|
|
|
6
6
|
export function utLayersToTree(layer: UTLayer[]): Tree<UTLayerWithoutChildren> {
|
|
7
|
-
return layer.map(
|
|
7
|
+
return layer.map(layer => ({
|
|
8
8
|
ref: {
|
|
9
9
|
name: layer.name,
|
|
10
10
|
docId: layer.docId,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { UTLayer } from
|
|
1
|
+
import type { UTLayer } from '../ut-tree/photoshopLayerDescriptorsToUTLayers';
|
|
2
2
|
|
|
3
|
-
export type UTLayerPickKeys<TKey extends keyof Omit<UTLayer,
|
|
3
|
+
export type UTLayerPickKeys<TKey extends keyof Omit<UTLayer, 'layers'>> = Pick<Omit<UTLayer, 'layers'>, TKey> & {
|
|
4
4
|
layers?: UTLayerPickKeys<TKey>[];
|
|
5
|
-
}
|
|
5
|
+
};
|
|
@@ -1,39 +1,40 @@
|
|
|
1
|
-
import type { Layer as DomLayer } from
|
|
2
|
-
import type { UTLayer } from
|
|
3
|
-
import { app } from
|
|
4
|
-
import { getFlattenedDomLayersList } from
|
|
1
|
+
import type { Layer as DomLayer } from 'photoshop';
|
|
2
|
+
import type { UTLayer } from '../ut-tree/photoshopLayerDescriptorsToUTLayers';
|
|
3
|
+
import { app } from 'photoshop';
|
|
4
|
+
import { getFlattenedDomLayersList } from '../dom/getFlattenedDomLayersList';
|
|
5
5
|
|
|
6
6
|
export function utLayerToDomLayer(layer: UTLayer): DomLayer {
|
|
7
|
-
const doc = app.documents.find(
|
|
7
|
+
const doc = app.documents.find(d => d.id === layer.docId);
|
|
8
8
|
if (!doc) {
|
|
9
9
|
throw new Error(`Document with id ${layer.docId} not found.`);
|
|
10
10
|
}
|
|
11
11
|
const allLayers = getFlattenedDomLayersList(doc.layers);
|
|
12
|
-
const domLayer = allLayers.find(
|
|
12
|
+
const domLayer = allLayers.find(l => l.id === layer.id);
|
|
13
13
|
if (!domLayer) {
|
|
14
14
|
throw new Error(
|
|
15
|
-
`Layer with id ${layer.id} not found in document ${layer.docId}
|
|
15
|
+
`Layer with id ${layer.id} not found in document ${layer.docId}.`,
|
|
16
16
|
);
|
|
17
17
|
}
|
|
18
18
|
return domLayer;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function utLayersToDomLayers(layers: UTLayer[]): DomLayer[] {
|
|
22
|
-
if (layers.length === 0)
|
|
22
|
+
if (layers.length === 0)
|
|
23
|
+
return [];
|
|
23
24
|
const docId = layers[0]!.docId;
|
|
24
|
-
if (!layers.every(
|
|
25
|
-
throw new Error(
|
|
25
|
+
if (!layers.every(l => l.docId === docId)) {
|
|
26
|
+
throw new Error('All layers must be from the same document.');
|
|
26
27
|
}
|
|
27
|
-
const doc = app.documents.find(
|
|
28
|
+
const doc = app.documents.find(d => d.id === docId);
|
|
28
29
|
if (!doc) {
|
|
29
30
|
throw new Error(`Document with id ${docId} not found.`);
|
|
30
31
|
}
|
|
31
32
|
const allLayers = getFlattenedDomLayersList(doc.layers);
|
|
32
33
|
return layers.map((l) => {
|
|
33
|
-
const domLayer = allLayers.find(
|
|
34
|
+
const domLayer = allLayers.find(dl => dl.id === l.id);
|
|
34
35
|
if (!domLayer) {
|
|
35
36
|
throw new Error(
|
|
36
|
-
`Layer with id ${l.id} not found in document ${docId}
|
|
37
|
+
`Layer with id ${l.id} not found in document ${docId}.`,
|
|
37
38
|
);
|
|
38
39
|
}
|
|
39
40
|
return domLayer;
|
package/test/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { photoshopLayerDescriptorsToUTLayersTest, photoshopLayerDescriptorsToUTLayersTest2 } from
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
1
|
+
import { renameLayerTest } from '../src/commands-library/renameLayer.uxp-test';
|
|
2
|
+
import { suspendHistoryTest } from '../src/core/suspendHistory.uxp-test';
|
|
3
|
+
import { sourcemapsTest } from '../src/error-sourcemaps/sourcemaps.uxp-test';
|
|
4
|
+
import { metadataStorageTest } from '../src/metadata-storage/metadataStorage.uxp-test';
|
|
5
|
+
import { applicationInfoTest } from '../src/other/applicationInfo.uxp-test';
|
|
6
|
+
import { clipboardTest } from '../src/other/clipboard.uxp-test';
|
|
7
|
+
import { backgroundLayerTest } from '../src/ut-tree/hasBackgroundLayer.uxp-test';
|
|
8
|
+
import { photoshopLayerDescriptorsToUTLayersTest, photoshopLayerDescriptorsToUTLayersTest2 } from '../src/ut-tree/photoshopLayerDescriptorsToUTLayers.uxp-test';
|
|
9
|
+
import { builtinModulesTest } from './meta-tests/builtinModules.uxp-test';
|
|
10
|
+
import { executeAsModalErrorTest } from './meta-tests/executeAsModal.uxp-test';
|
|
11
|
+
import { suspendHistoryErrorTest } from './meta-tests/suspendHistory.uxp-test';
|
|
12
12
|
|
|
13
13
|
export const tests = [
|
|
14
14
|
applicationInfoTest,
|
|
@@ -1,42 +1,44 @@
|
|
|
1
|
-
import type { Test } from
|
|
2
|
-
import { expect } from
|
|
1
|
+
import type { Test } from '@bubblydoo/uxp-test-framework';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
3
|
|
|
4
4
|
export const builtinModulesTest: Test = {
|
|
5
|
-
name:
|
|
5
|
+
name: 'meta: some builtin modules should be available',
|
|
6
6
|
async run() {
|
|
7
7
|
const testModules = [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
'photoshop',
|
|
9
|
+
'uxp',
|
|
10
|
+
'fs',
|
|
11
|
+
'os',
|
|
12
|
+
'path',
|
|
13
|
+
'process',
|
|
14
|
+
'shell',
|
|
15
|
+
'http',
|
|
16
|
+
'https',
|
|
17
|
+
'url',
|
|
18
|
+
'util',
|
|
19
|
+
'crypto',
|
|
20
|
+
'stream',
|
|
21
|
+
'zlib',
|
|
22
22
|
];
|
|
23
23
|
const successModules = testModules.filter(module => doesImportExist(module));
|
|
24
24
|
expect(successModules).to.deep.eq([
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
]);
|
|
25
|
+
'photoshop',
|
|
26
|
+
'uxp',
|
|
27
|
+
'fs',
|
|
28
|
+
'os',
|
|
29
|
+
'path',
|
|
30
|
+
'process',
|
|
31
|
+
]);
|
|
32
32
|
},
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
function doesImportExist(module: string) {
|
|
36
36
|
try {
|
|
37
|
+
// eslint-disable-next-line ts/no-require-imports
|
|
37
38
|
require(module);
|
|
38
39
|
return true;
|
|
39
|
-
}
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
40
42
|
return false;
|
|
41
43
|
}
|
|
42
|
-
}
|
|
44
|
+
}
|
|
@@ -1,37 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import type { Test } from '@bubblydoo/uxp-test-framework';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { core } from 'photoshop';
|
|
4
4
|
|
|
5
5
|
export const executeAsModalErrorTest: Test = {
|
|
6
|
-
name:
|
|
6
|
+
name: 'meta: executeAsModal should throw correctly',
|
|
7
7
|
async run() {
|
|
8
8
|
let threw = false;
|
|
9
9
|
try {
|
|
10
10
|
await core.executeAsModal(
|
|
11
11
|
async () => {
|
|
12
|
-
throw new Error(
|
|
12
|
+
throw new Error('Uncaught error');
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
|
-
commandName:
|
|
16
|
-
}
|
|
15
|
+
commandName: 'Test',
|
|
16
|
+
},
|
|
17
17
|
);
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
|
+
catch (_e) {
|
|
19
20
|
threw = true;
|
|
20
21
|
}
|
|
22
|
+
// eslint-disable-next-line ts/no-unused-expressions
|
|
21
23
|
expect(threw).to.be.true;
|
|
22
24
|
},
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
export const executeAsModalReturnTest: Test = {
|
|
26
|
-
name:
|
|
28
|
+
name: 'meta: executeAsModal should return correctly',
|
|
27
29
|
async run() {
|
|
28
30
|
const result = await core.executeAsModal(
|
|
29
31
|
async () => {
|
|
30
|
-
return 'test'
|
|
32
|
+
return 'test';
|
|
31
33
|
},
|
|
32
34
|
{
|
|
33
|
-
commandName:
|
|
34
|
-
}
|
|
35
|
+
commandName: 'Test',
|
|
36
|
+
},
|
|
35
37
|
);
|
|
36
38
|
expect(result).to.equal('test');
|
|
37
39
|
},
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import type { Test } from '@bubblydoo/uxp-test-framework';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { app } from 'photoshop';
|
|
4
4
|
|
|
5
5
|
export const suspendHistoryErrorTest: Test = {
|
|
6
|
-
name:
|
|
6
|
+
name: 'meta: suspendHistory should throw correctly',
|
|
7
7
|
async run() {
|
|
8
8
|
const document = app.activeDocument;
|
|
9
9
|
if (!document) {
|
|
10
|
-
throw new Error(
|
|
10
|
+
throw new Error('No active document');
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
let threw = false;
|
|
14
14
|
try {
|
|
15
15
|
await document.suspendHistory(
|
|
16
16
|
async (context) => {
|
|
17
|
-
throw new Error(
|
|
17
|
+
throw new Error('Uncaught error');
|
|
18
18
|
},
|
|
19
|
-
|
|
19
|
+
'Test',
|
|
20
20
|
);
|
|
21
|
-
}
|
|
21
|
+
}
|
|
22
|
+
catch (_e) {
|
|
22
23
|
threw = true;
|
|
23
24
|
}
|
|
25
|
+
// eslint-disable-next-line ts/no-unused-expressions
|
|
24
26
|
expect(threw).to.be.true;
|
|
25
27
|
},
|
|
26
28
|
};
|
|
27
|
-
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "@bubblydoo/tsconfig/tsconfig.base.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"allowJs": true,
|
|
5
4
|
"moduleDetection": "force",
|
|
6
|
-
"verbatimModuleSyntax": true,
|
|
7
|
-
"noUncheckedIndexedAccess": true,
|
|
8
|
-
"noImplicitOverride": true,
|
|
9
5
|
"rootDir": ".",
|
|
10
|
-
"typeRoots": ["./node_modules/@adobe-uxp-types", "./node_modules/@types"]
|
|
6
|
+
"typeRoots": ["./node_modules/@adobe-uxp-types", "./node_modules/@types"],
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"noImplicitOverride": true,
|
|
9
|
+
"noUncheckedIndexedAccess": true,
|
|
10
|
+
"verbatimModuleSyntax": true
|
|
11
11
|
},
|
|
12
12
|
"include": ["src", "test"]
|
|
13
13
|
}
|
package/tsup.config.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { defineConfig } from
|
|
1
|
+
import { defineConfig } from 'tsup';
|
|
2
2
|
|
|
3
3
|
export default defineConfig({
|
|
4
|
-
entry: [
|
|
5
|
-
format:
|
|
4
|
+
entry: ['src/index.ts', 'src/commands-library/index.ts'],
|
|
5
|
+
format: 'esm',
|
|
6
6
|
dts: true,
|
|
7
|
-
external: [
|
|
8
|
-
outDir:
|
|
7
|
+
external: ['photoshop', 'uxp'],
|
|
8
|
+
outDir: 'dist',
|
|
9
9
|
});
|
package/uxp-tests.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Plugin } from
|
|
2
|
-
import dedent from
|
|
1
|
+
import type { Plugin } from 'vitest/config';
|
|
2
|
+
import dedent from 'dedent';
|
|
3
3
|
|
|
4
4
|
const nativeModules = [
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
'photoshop',
|
|
6
|
+
'uxp',
|
|
7
7
|
];
|
|
8
8
|
|
|
9
|
-
const pluginPrefix =
|
|
9
|
+
const pluginPrefix = 'photoshop-builtin';
|
|
10
10
|
|
|
11
11
|
const minimalModules = {
|
|
12
12
|
photoshop: dedent`
|
|
@@ -18,24 +18,26 @@ export const app = UNIMPLEMENTED;
|
|
|
18
18
|
export const entrypoints = UNIMPLEMENTED;
|
|
19
19
|
export const storage = UNIMPLEMENTED;
|
|
20
20
|
`,
|
|
21
|
-
}
|
|
21
|
+
};
|
|
22
22
|
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
export function vitestPhotoshopAliasPlugin(): Plugin {
|
|
24
|
+
return {
|
|
25
|
+
name: 'vitest-photoshop-alias',
|
|
26
|
+
resolveId(id) {
|
|
27
|
+
if (nativeModules.includes(id)) {
|
|
28
|
+
return `${id}?${pluginPrefix}`;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
load(id) {
|
|
32
|
+
if (id.endsWith(`?${pluginPrefix}`)) {
|
|
33
|
+
const origModuleId = id.replace(`?${pluginPrefix}`, '');
|
|
34
|
+
const mod = dedent`
|
|
34
35
|
// This is a photoshop builtin module, not available in Vitest. This is an alias to provide minimal compatibility.
|
|
35
36
|
const UNIMPLEMENTED = { __vitest_photoshop_alias_unimplemented__: true };
|
|
36
37
|
${minimalModules[origModuleId]}
|
|
37
38
|
`;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
39
|
+
return mod;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
package/vitest.config.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { defineConfig } from
|
|
2
|
-
import { vitestPhotoshopAliasPlugin } from
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
import { vitestPhotoshopAliasPlugin } from './vitest-photoshop-alias-plugin';
|
|
3
3
|
|
|
4
4
|
export default defineConfig({
|
|
5
5
|
test: {
|
|
6
|
-
include: [
|
|
7
|
-
reporters: process.env.CI ? [
|
|
6
|
+
include: ['src/**/*.test.ts'],
|
|
7
|
+
reporters: process.env.CI ? ['default', 'junit'] : ['default'],
|
|
8
8
|
outputFile: {
|
|
9
|
-
junit:
|
|
9
|
+
junit: './test-results/junit.xml',
|
|
10
10
|
},
|
|
11
11
|
typecheck: {
|
|
12
12
|
enabled: true,
|
|
13
|
-
include: [
|
|
13
|
+
include: ['src/**/*.test-d.ts'],
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
plugins: [vitestPhotoshopAliasPlugin()],
|