@atlaskit/adf-utils 16.0.0 → 17.0.0

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/builders/package.json +1 -0
  3. package/codemods/17.0.0-update-imports-to-new-entry-points.ts +175 -0
  4. package/codemods/__tests__/next-update-imports-to-new-entry-points.ts +175 -0
  5. package/codemods/helpers/entry-points.ts +33 -0
  6. package/codemods/types/entry-points.ts +12 -0
  7. package/dist/cjs/index.js +1 -447
  8. package/dist/cjs/scrub/scrub-content.js +5 -5
  9. package/dist/cjs/transforms/dedupe-marks-transform.js +120 -0
  10. package/dist/cjs/transforms/indentation-marks-transform.js +66 -0
  11. package/dist/cjs/{media-link-transform.js → transforms/media-link-transform.js} +1 -1
  12. package/dist/cjs/transforms/nodes-missing-content-transform.js +205 -0
  13. package/dist/cjs/transforms.js +45 -0
  14. package/dist/cjs/version.json +1 -1
  15. package/dist/es2019/index.js +2 -7
  16. package/dist/es2019/transforms/dedupe-marks-transform.js +97 -0
  17. package/dist/es2019/transforms/indentation-marks-transform.js +45 -0
  18. package/dist/es2019/{media-link-transform.js → transforms/media-link-transform.js} +1 -1
  19. package/dist/es2019/transforms/nodes-missing-content-transform.js +175 -0
  20. package/dist/es2019/transforms.js +5 -0
  21. package/dist/es2019/version.json +1 -1
  22. package/dist/esm/index.js +2 -7
  23. package/dist/esm/scrub/scrub-content.js +5 -5
  24. package/dist/esm/transforms/dedupe-marks-transform.js +108 -0
  25. package/dist/esm/transforms/indentation-marks-transform.js +55 -0
  26. package/dist/esm/{media-link-transform.js → transforms/media-link-transform.js} +1 -1
  27. package/dist/esm/transforms/nodes-missing-content-transform.js +192 -0
  28. package/dist/esm/transforms.js +5 -0
  29. package/dist/esm/version.json +1 -1
  30. package/dist/types/builders/marks/breakout.d.ts +1 -1
  31. package/dist/types/index.d.ts +1 -9
  32. package/dist/types/transforms/dedupe-marks-transform.d.ts +8 -0
  33. package/dist/types/transforms/indentation-marks-transform.d.ts +7 -0
  34. package/dist/types/{media-link-transform.d.ts → transforms/media-link-transform.d.ts} +1 -1
  35. package/dist/types/transforms/nodes-missing-content-transform.d.ts +7 -0
  36. package/dist/types/transforms.d.ts +5 -0
  37. package/dist/types/validator.d.ts +0 -1
  38. package/empty-adf/package.json +1 -0
  39. package/package.json +15 -4
  40. package/scrub/package.json +1 -0
  41. package/transforms/package.json +8 -0
  42. package/traverse/package.json +1 -0
  43. package/tsconfig.json +2 -1
  44. package/types/package.json +8 -0
  45. package/validator/package.json +1 -0
  46. package/validatorTypes/package.json +8 -0
  47. package/media-link-transform/package.json +0 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,84 @@
1
1
  # @atlaskit/adf-utils
2
2
 
3
+ ## 17.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [`844b8278b4d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/844b8278b4d) - ED-14608: Migrate adf-utils to modern child entry points, remove default entry point, add codemods to enforce migration.
8
+
9
+ As we will no longer support the default entry point, imports such as the example below:
10
+
11
+ ```
12
+ import { breakout, scrubAdf, map } from '@atlaskit/adf-utils';
13
+ ```
14
+
15
+ would need to become:
16
+
17
+ ```
18
+ import { breakout } from '@atlaskit/adf-utils/builders';
19
+ import { scrubADF } from '@atlaskit/adf-utils/scrub';
20
+ import { map } from '@atlaskit/adf-utils/traverse';
21
+ ```
22
+
23
+ **The new (and only) @atlaskit/adf-utils entry points supported now are listed below:**
24
+
25
+ @atlaskit/adf-utils/builders for:
26
+
27
+ - breakout, code, em, link, link, strike, strong, strong, subsup, text-color, underline, underline, alignment, indentation, data-consumer fragment, blockquote, bodied-extension, block-card, bullet-list, bullet-list, code-block, date, decision-item, decision-list, doc, emoji, extension, expand, nested-expand, hard-break, hard-break, heading, inline-extension, inline-card, layout-column, layout-section, list-item, list-item, media-group, media-single, media, mention, ordered-list, ordered-list, panel, paragraph, paragraph, placeholder, rule, rule, status, table-cell, table-cell, table-header, table-header, table-row, table-row, table, task-item, task-list, text, embed-card,
28
+
29
+ @atlaskit/adf-utils/empty-adf for:
30
+
31
+ - getEmptyADF
32
+
33
+ @atlaskit/adf-utils/scrub for:
34
+
35
+ - scrubAdf
36
+
37
+ @atlaskit/adf-utils/transforms for:
38
+
39
+ - transformMediaLinkMarks, transformTextLinkCodeMarks, transformDedupeMarks, transformNodesMissingContent, transformIndentationMarks
40
+
41
+ @atlaskit/adf-utils/traverse for:
42
+
43
+ - traverse, map, reduce, filter
44
+
45
+ @atlaskit/adf-utils/validator for:
46
+
47
+ - validateAttrs, validator
48
+
49
+ @atlaskit/adf-utils/types for:
50
+
51
+ - ADFEntityMark, ADFEntity, Visitor, VisitorCollection, EntityParent
52
+
53
+ @atlaskit/adf-utils/validatorTypes for:
54
+
55
+ - MarkValidationResult, Output, NodeValidationResult, ValidatorContent, AttributesSpec, ValidatorSpec, ValidationErrorMap, RequiredContentLength, Content, ValidationErrorType, ValidationError, ErrorCallback, ValidationMode, ValidationOptions, SpecValidatorResult, Err, ErrorCallbackOptions, Validate
56
+
57
+ **Since there are significant changes (including the breaking change of dropping the default entry point to @atlaskit/adf-utils), we will be providing a codemod to help consumers upgrade their usage of adf-utils**
58
+
59
+ Once you've upgraded `@atlaskit/adf-utils`, use the Atlaskit codemod CLI.
60
+
61
+ `npx @atlaskit/codemod-cli /path/to/target/directory`
62
+
63
+ See [documentation on DAC](https://developer.atlassian.com/cloud/framework/atlassian-frontend/codemods/01-atlassian-codemods/) for general codemod guidance.
64
+
65
+ ### Patch Changes
66
+
67
+ - [`8300a668772`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8300a668772) - [ux] ED-14488: Extend ADF sanitising coverage to prevent Prosemirror failing validation checks on adf that can be repaired
68
+ - Updated dependencies
69
+
70
+ ## 16.0.2
71
+
72
+ ### Patch Changes
73
+
74
+ - [`cb2392f6d33`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cb2392f6d33) - Upgrade to TypeScript 4.2.4
75
+
76
+ ## 16.0.1
77
+
78
+ ### Patch Changes
79
+
80
+ - Updated dependencies
81
+
3
82
  ## 16.0.0
4
83
 
5
84
  ### Major Changes
@@ -3,5 +3,6 @@
3
3
  "main": "../dist/cjs/builders.js",
4
4
  "module": "../dist/esm/builders.js",
5
5
  "module:es2019": "../dist/es2019/builders.js",
6
+ "sideEffects": false,
6
7
  "types": "../dist/types/builders.d.ts"
7
8
  }
@@ -0,0 +1,175 @@
1
+ import { createTransformer } from '@atlaskit/codemod-utils';
2
+ import { createMigratesFromEntryPointChangeRequests } from './helpers/entry-points';
3
+ import type { EntryPointChangeRequest } from './types/entry-points';
4
+
5
+ const DEFAULT_ADF_UTILS_IMPORT = '@atlaskit/adf-utils';
6
+
7
+ const types: EntryPointChangeRequest = {
8
+ importSpecifiers: [
9
+ 'ADFEntity',
10
+ 'ADFEntityMark',
11
+ 'Visitor',
12
+ 'VisitorCollection',
13
+ ],
14
+ oldEntryPointsToRemove: [DEFAULT_ADF_UTILS_IMPORT],
15
+ newEntryPoint: `${DEFAULT_ADF_UTILS_IMPORT}/types`,
16
+ shouldBeTypeImport: true,
17
+ };
18
+
19
+ const validatorTypes: EntryPointChangeRequest = {
20
+ importSpecifiers: [
21
+ 'Content',
22
+ 'ErrorCallback',
23
+ 'Output',
24
+ 'ValidationError',
25
+ 'ValidationErrorMap',
26
+ 'ValidationErrorType',
27
+ 'ValidationMode',
28
+ 'ValidationOptions',
29
+ 'ErrorCallbackOptions',
30
+ 'Validate',
31
+ 'NodeValidationResult',
32
+ 'ValidatorSpec',
33
+ 'AttributesSpec',
34
+ 'ValidatorContent',
35
+ 'MarkValidationResult',
36
+ 'SpecValidatorResult',
37
+ 'Err',
38
+ ],
39
+ oldEntryPointsToRemove: [
40
+ DEFAULT_ADF_UTILS_IMPORT,
41
+ `${DEFAULT_ADF_UTILS_IMPORT}/validator`,
42
+ ],
43
+ newEntryPoint: `${DEFAULT_ADF_UTILS_IMPORT}/validatorTypes`,
44
+ shouldBeTypeImport: true,
45
+ };
46
+
47
+ const transforms: EntryPointChangeRequest = {
48
+ importSpecifiers: [
49
+ 'transformMediaLinkMarks',
50
+ 'transformTextLinkCodeMarks',
51
+ 'transformDedupeMarks',
52
+ 'transformNodesMissingContent',
53
+ 'transformIndentationMarks',
54
+ ],
55
+ oldEntryPointsToRemove: [DEFAULT_ADF_UTILS_IMPORT],
56
+ newEntryPoint: `${DEFAULT_ADF_UTILS_IMPORT}/transforms`,
57
+ shouldBeTypeImport: false,
58
+ };
59
+
60
+ const traverse: EntryPointChangeRequest = {
61
+ importSpecifiers: ['traverse', 'map', 'reduce', 'filter'],
62
+ oldEntryPointsToRemove: [DEFAULT_ADF_UTILS_IMPORT],
63
+ newEntryPoint: `${DEFAULT_ADF_UTILS_IMPORT}/traverse`,
64
+ shouldBeTypeImport: false,
65
+ };
66
+
67
+ const builders: EntryPointChangeRequest = {
68
+ importSpecifiers: [
69
+ 'a',
70
+ 'alignment',
71
+ 'b',
72
+ 'blockCard',
73
+ 'blockQuote',
74
+ 'bodiedExtension',
75
+ 'br',
76
+ 'breakout',
77
+ 'bulletList',
78
+ 'code',
79
+ 'codeBlock',
80
+ 'date',
81
+ 'decisionItem',
82
+ 'decisionList',
83
+ 'doc',
84
+ 'em',
85
+ 'embedCard',
86
+ 'emoji',
87
+ 'expand',
88
+ 'extension',
89
+ 'hardBreak',
90
+ 'heading',
91
+ 'hr',
92
+ 'indentation',
93
+ 'inlineCard',
94
+ 'inlineExtension',
95
+ 'layoutColumn',
96
+ 'layoutSection',
97
+ 'li',
98
+ 'link',
99
+ 'listItem',
100
+ 'media',
101
+ 'mediaGroup',
102
+ 'mediaSingle',
103
+ 'mention',
104
+ 'nestedExpand',
105
+ 'ol',
106
+ 'orderedList',
107
+ 'p',
108
+ 'panel',
109
+ 'paragraph',
110
+ 'placeholder',
111
+ 'rule',
112
+ 'status',
113
+ 'strike',
114
+ 'strong',
115
+ 'subsup',
116
+ 'table',
117
+ 'tableCell',
118
+ 'tableHeader',
119
+ 'tableRow',
120
+ 'taskItem',
121
+ 'taskList',
122
+ 'td',
123
+ 'text',
124
+ 'textColor',
125
+ 'th',
126
+ 'tr',
127
+ 'u',
128
+ 'ul',
129
+ 'underline',
130
+ 'dataConsumer',
131
+ ],
132
+ oldEntryPointsToRemove: [DEFAULT_ADF_UTILS_IMPORT],
133
+ newEntryPoint: `${DEFAULT_ADF_UTILS_IMPORT}/builders`,
134
+ shouldBeTypeImport: false,
135
+ };
136
+
137
+ const emptyAdf: EntryPointChangeRequest = {
138
+ importSpecifiers: ['getEmptyADF'],
139
+ oldEntryPointsToRemove: [DEFAULT_ADF_UTILS_IMPORT],
140
+ newEntryPoint: `${DEFAULT_ADF_UTILS_IMPORT}/empty-adf`,
141
+ shouldBeTypeImport: false,
142
+ };
143
+
144
+ const validator: EntryPointChangeRequest = {
145
+ importSpecifiers: ['validator', 'validateAttrs'],
146
+ oldEntryPointsToRemove: [DEFAULT_ADF_UTILS_IMPORT],
147
+ newEntryPoint: `${DEFAULT_ADF_UTILS_IMPORT}/validator`,
148
+ shouldBeTypeImport: false,
149
+ };
150
+
151
+ const scrub: EntryPointChangeRequest = {
152
+ importSpecifiers: ['scrubAdf'],
153
+ oldEntryPointsToRemove: [DEFAULT_ADF_UTILS_IMPORT],
154
+ newEntryPoint: `${DEFAULT_ADF_UTILS_IMPORT}/scrub`,
155
+ shouldBeTypeImport: false,
156
+ };
157
+
158
+ const entryPointChangeRequests: EntryPointChangeRequest[] = [
159
+ transforms,
160
+ validatorTypes,
161
+ types,
162
+ traverse,
163
+ builders,
164
+ validator,
165
+ emptyAdf,
166
+ scrub,
167
+ ];
168
+
169
+ export const entryPointChangeMigrates = createMigratesFromEntryPointChangeRequests(
170
+ entryPointChangeRequests,
171
+ );
172
+
173
+ const transformer = createTransformer(entryPointChangeMigrates);
174
+
175
+ export default transformer;
@@ -0,0 +1,175 @@
1
+ import transformer from '../17.0.0-update-imports-to-new-entry-points';
2
+
3
+ const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
4
+
5
+ describe('updates adf-util imports to new child entry points', () => {
6
+ defineInlineTest(
7
+ { default: transformer, parser: 'tsx' },
8
+ {},
9
+ `
10
+ import { traverse } from "@atlaskit/adf-utils";
11
+ import { ADFEntity, ADFEntityMark } from "@atlaskit/adf-utils";
12
+ import { validateAttrs, validator, ValidationErrorMap } from '@atlaskit/adf-utils';
13
+ import type { NodeValidationResult } from '@atlaskit/adf-utils';
14
+ import { type ValidationMode } from '@atlaskit/adf-utils';
15
+
16
+ export default () => (
17
+ <div>
18
+ hello
19
+ </div>
20
+ );
21
+ `,
22
+ `
23
+ import type { ValidationErrorMap, ValidationMode, NodeValidationResult } from "@atlaskit/adf-utils/validatorTypes";
24
+ import type { ADFEntity, ADFEntityMark } from "@atlaskit/adf-utils/types";
25
+ import { traverse } from "@atlaskit/adf-utils/traverse";
26
+ import { validator, validateAttrs } from "@atlaskit/adf-utils/validator";
27
+
28
+ export default () => (
29
+ <div>
30
+ hello
31
+ </div>
32
+ );
33
+ `,
34
+ 'should handle migrating any combination of old entry points (including type imports and imports with type modifiers) to new child entry points',
35
+ );
36
+
37
+ defineInlineTest(
38
+ { default: transformer, parser: 'tsx' },
39
+ {},
40
+ `
41
+ import { traverse, teamRocketAndMeowth, scrubAdf } from "@atlaskit/adf-utils";
42
+ import { Pokemon, ADFEntityMark, AshKetchum } from "@atlaskit/adf-utils";
43
+ import type { PsyDuck } from "@atlaskit/adf-utils/pokemon-types";
44
+ import Boogeyman from "@deep/the-mariana-trench";
45
+
46
+ export default () => (
47
+ <div>
48
+ hello
49
+ </div>
50
+ );
51
+ `,
52
+ `
53
+ import type { ADFEntityMark } from "@atlaskit/adf-utils/types";
54
+ import { traverse } from "@atlaskit/adf-utils/traverse";
55
+ import { scrubAdf } from "@atlaskit/adf-utils/scrub";
56
+ import { teamRocketAndMeowth } from "@atlaskit/adf-utils";
57
+ import { Pokemon, AshKetchum } from "@atlaskit/adf-utils";
58
+ import type { PsyDuck } from "@atlaskit/adf-utils/pokemon-types";
59
+ import Boogeyman from "@deep/the-mariana-trench";
60
+
61
+ export default () => (
62
+ <div>
63
+ hello
64
+ </div>
65
+ );
66
+ `,
67
+ 'should leave unknown entry points or import specifiers untouched (and unmerged if initially unmerged)',
68
+ );
69
+
70
+ defineInlineTest(
71
+ { default: transformer, parser: 'tsx' },
72
+ {},
73
+ `
74
+ import { VisitorCollection } from "@atlaskit/adf-utils/types";
75
+ import type { Visitor } from "@atlaskit/adf-utils";
76
+
77
+ export default () => (
78
+ <div>
79
+ hello
80
+ </div>
81
+ );
82
+ `,
83
+ `
84
+ import type { VisitorCollection, Visitor } from "@atlaskit/adf-utils/types";
85
+
86
+ export default () => (
87
+ <div>
88
+ hello
89
+ </div>
90
+ );
91
+ `,
92
+ 'should handle migrating new child entry points with mismatched importKinds (e.g. non-type when should be type import)',
93
+ );
94
+
95
+ defineInlineTest(
96
+ { default: transformer, parser: 'tsx' },
97
+ {},
98
+ `
99
+ import { scrubAdf, doc, p, link } from "@atlaskit/adf-utils";
100
+ import { blockCard, paragraph } from "@atlaskit/adf-utils/builders";
101
+ import { placeholder, transformDedupeMarks } from "@atlaskit/adf-utils";
102
+ import { VisitorCollection } from "@atlaskit/adf-utils/types";
103
+ import type { Visitor } from "@atlaskit/adf-utils";
104
+ import { getEmptyADF } from "@atlaskit/adf-utils";
105
+
106
+ export default () => (
107
+ <div>
108
+ hello
109
+ </div>
110
+ );
111
+ `,
112
+ `
113
+ import { transformDedupeMarks } from "@atlaskit/adf-utils/transforms";
114
+ import { getEmptyADF } from "@atlaskit/adf-utils/empty-adf";
115
+ import { scrubAdf } from "@atlaskit/adf-utils/scrub";
116
+ import { blockCard, paragraph, doc, link, p, placeholder } from "@atlaskit/adf-utils/builders";
117
+ import type { VisitorCollection, Visitor } from "@atlaskit/adf-utils/types";
118
+
119
+ export default () => (
120
+ <div>
121
+ hello
122
+ </div>
123
+ );
124
+ `,
125
+ 'should handle migrating any combination of old and new entry points to new child entry points',
126
+ );
127
+
128
+ defineInlineTest(
129
+ { default: transformer, parser: 'tsx' },
130
+ {},
131
+ `
132
+ const { scrubAdf } = require("@atlaskit/adf-utils");
133
+ import * as adfUtils from "@atlaskit/adf-utils";
134
+
135
+ export default () => {
136
+ if (shouldFetchModule) {
137
+ import("@atlaskit/adf-utils").then(module => ({
138
+ something: "else"
139
+ }));
140
+ import("@atlaskit/adf-utils/traverse").then(module => {
141
+ const traverse = module.traverse;
142
+ traverse();
143
+ });
144
+ }
145
+ return (
146
+ <div>
147
+ hello
148
+ </div>
149
+ )
150
+ }
151
+ `,
152
+ `
153
+ const { scrubAdf } = require("@atlaskit/adf-utils");
154
+ import * as adfUtils from "@atlaskit/adf-utils";
155
+
156
+ export default () => {
157
+ if (shouldFetchModule) {
158
+ import("@atlaskit/adf-utils").then(module => ({
159
+ something: "else"
160
+ }));
161
+ import("@atlaskit/adf-utils/traverse").then(module => {
162
+ const traverse = module.traverse;
163
+ traverse();
164
+ });
165
+ }
166
+ return (
167
+ <div>
168
+ hello
169
+ </div>
170
+ )
171
+ }
172
+ `,
173
+ 'should skip migrating other import syntaxes (namespace imports, CJS, dyamic imports)',
174
+ );
175
+ });
@@ -0,0 +1,33 @@
1
+ import { changeImportEntryPoint } from '@atlaskit/codemod-utils';
2
+ import type {
3
+ EntryPointChangeRequest,
4
+ EntryPointChangeMigrates,
5
+ } from '../types/entry-points';
6
+
7
+ export const createMigratesFromEntryPointChangeRequests = (
8
+ changeRequests: EntryPointChangeRequest[],
9
+ ) => {
10
+ const entryPointChangeMigrates: EntryPointChangeMigrates = [];
11
+ changeRequests.forEach(
12
+ ({
13
+ importSpecifiers,
14
+ oldEntryPointsToRemove,
15
+ newEntryPoint,
16
+ shouldBeTypeImport,
17
+ }) => {
18
+ oldEntryPointsToRemove.forEach((oldEntryPoint) => {
19
+ importSpecifiers.forEach((importSpecifier) => {
20
+ entryPointChangeMigrates.push(
21
+ changeImportEntryPoint(
22
+ oldEntryPoint,
23
+ importSpecifier,
24
+ newEntryPoint,
25
+ shouldBeTypeImport,
26
+ ),
27
+ );
28
+ });
29
+ });
30
+ },
31
+ );
32
+ return entryPointChangeMigrates;
33
+ };
@@ -0,0 +1,12 @@
1
+ import type { changeImportEntryPoint } from '@atlaskit/codemod-utils';
2
+
3
+ export type EntryPointChangeRequest = {
4
+ importSpecifiers: string[];
5
+ oldEntryPointsToRemove: string[];
6
+ newEntryPoint: string;
7
+ shouldBeTypeImport: boolean;
8
+ };
9
+
10
+ export type EntryPointChange = ReturnType<typeof changeImportEntryPoint>;
11
+
12
+ export type EntryPointChangeMigrates = EntryPointChange[];