@atlaskit/codemod-cli 0.11.5 → 0.12.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/cli.js +75 -68
  3. package/dist/cjs/filepath.js +29 -69
  4. package/dist/cjs/index.js +3 -3
  5. package/dist/cjs/main.js +167 -337
  6. package/dist/cjs/presets/css-to-design-tokens/css-to-design-tokens.js +31 -73
  7. package/dist/cjs/presets/css-to-design-tokens/utils/legacy-colors.js +3 -3
  8. package/dist/cjs/presets/css-to-design-tokens/utils/meta.js +6 -19
  9. package/dist/cjs/presets/index.js +1 -3
  10. package/dist/cjs/presets/styled-to-emotion/styled-to-emotion.js +12 -19
  11. package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +32 -61
  12. package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +13 -26
  13. package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +7 -11
  14. package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +6 -10
  15. package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +3 -3
  16. package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +1 -1
  17. package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +2 -16
  18. package/dist/cjs/sinceRef.js +35 -70
  19. package/dist/cjs/transforms.js +26 -44
  20. package/dist/cjs/types.js +3 -27
  21. package/dist/cjs/utils.js +6 -6
  22. package/dist/cjs/version.json +1 -1
  23. package/dist/es2019/version.json +1 -1
  24. package/dist/esm/cli.js +53 -55
  25. package/dist/esm/filepath.js +50 -54
  26. package/dist/esm/main.js +220 -230
  27. package/dist/esm/presets/css-to-design-tokens/css-to-design-tokens.js +11 -13
  28. package/dist/esm/sinceRef.js +48 -50
  29. package/dist/esm/version.json +1 -1
  30. package/dist/types-ts4.0/cli.d.ts +1 -0
  31. package/dist/types-ts4.0/filepath.d.ts +2 -0
  32. package/dist/types-ts4.0/index.d.ts +4 -0
  33. package/dist/types-ts4.0/main.d.ts +19 -0
  34. package/dist/types-ts4.0/presets/css-to-design-tokens/css-to-design-tokens.d.ts +2 -0
  35. package/dist/types-ts4.0/presets/css-to-design-tokens/utils/legacy-colors.d.ts +3 -0
  36. package/dist/types-ts4.0/presets/css-to-design-tokens/utils/meta.d.ts +1 -0
  37. package/dist/types-ts4.0/presets/index.d.ts +9 -0
  38. package/dist/types-ts4.0/presets/styled-to-emotion/styled-to-emotion.d.ts +6 -0
  39. package/dist/types-ts4.0/presets/theme-to-design-tokens/theme-to-design-tokens.d.ts +2 -0
  40. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/ast-meta.d.ts +3 -0
  41. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/ast.d.ts +3 -0
  42. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/color.d.ts +4 -0
  43. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/fuzzy-search.d.ts +5 -0
  44. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/legacy-colors.d.ts +3 -0
  45. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/named-colors.d.ts +1 -0
  46. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/tokens.d.ts +2 -0
  47. package/dist/types-ts4.0/sinceRef.d.ts +5 -0
  48. package/dist/types-ts4.0/transforms.d.ts +10 -0
  49. package/dist/types-ts4.0/types.d.ts +59 -0
  50. package/dist/types-ts4.0/utils.d.ts +1 -0
  51. package/package.json +2 -2
@@ -160,19 +160,17 @@ export default function transformer(_x) {
160
160
  function _transformer() {
161
161
  _transformer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(file) {
162
162
  return _regeneratorRuntime.wrap(function _callee$(_context) {
163
- while (1) {
164
- switch (_context.prev = _context.next) {
165
- case 0:
166
- _context.next = 2;
167
- return postcss([plugin()]).process(file.source, {
168
- syntax: lessSyntax
169
- }).css;
170
- case 2:
171
- return _context.abrupt("return", _context.sent);
172
- case 3:
173
- case "end":
174
- return _context.stop();
175
- }
163
+ while (1) switch (_context.prev = _context.next) {
164
+ case 0:
165
+ _context.next = 2;
166
+ return postcss([plugin()]).process(file.source, {
167
+ syntax: lessSyntax
168
+ }).css;
169
+ case 2:
170
+ return _context.abrupt("return", _context.sent);
171
+ case 3:
172
+ case "end":
173
+ return _context.stop();
176
174
  }
177
175
  }, _callee);
178
176
  }));
@@ -23,56 +23,54 @@ export var getPackagesSinceRef = /*#__PURE__*/function () {
23
23
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(ref) {
24
24
  var git, commit, diff, modifiedPackages, addedPackages, upgradedPackages;
25
25
  return _regeneratorRuntime.wrap(function _callee$(_context) {
26
- while (1) {
27
- switch (_context.prev = _context.next) {
28
- case 0:
29
- git = simpleGit();
30
- _context.prev = 1;
31
- _context.next = 4;
32
- return git.revparse(['--verify', ref]);
33
- case 4:
34
- commit = _context.sent;
35
- _context.next = 10;
36
- break;
37
- case 7:
38
- _context.prev = 7;
39
- _context.t0 = _context["catch"](1);
40
- throw new ValidationError("Invalid git ref \"".concat(ref, "\""));
41
- case 10:
42
- _context.next = 12;
43
- return git.diff([commit, '--', 'package.json']);
44
- case 12:
45
- diff = _context.sent;
46
- modifiedPackages = diff.split('\n').map(parseDiffLine).filter(function (pkg) {
47
- return Boolean(pkg);
48
- });
49
- addedPackages = new Map(modifiedPackages.filter(function (pkg) {
50
- return pkg.type === 'added';
51
- }).map(function (pkg) {
52
- return [pkg.name, pkg];
53
- }));
54
- /* This is holds the previous version of packages that have been upgraded. Packages are treated as
55
- * upgraded if they have both an addition/deletion entry in the diff and their versions differ
56
- */
57
- upgradedPackages = modifiedPackages.filter(function (pkg) {
58
- var addedEntry = addedPackages.get(pkg.name);
59
- if (pkg.type !== 'deleted' || !addedEntry) {
60
- return false;
61
- }
62
- return pkg.version !== addedEntry.version;
63
- }).map(function (_ref2) {
64
- var name = _ref2.name,
65
- version = _ref2.version;
66
- return {
67
- name: name,
68
- version: version
69
- };
70
- });
71
- return _context.abrupt("return", upgradedPackages);
72
- case 17:
73
- case "end":
74
- return _context.stop();
75
- }
26
+ while (1) switch (_context.prev = _context.next) {
27
+ case 0:
28
+ git = simpleGit();
29
+ _context.prev = 1;
30
+ _context.next = 4;
31
+ return git.revparse(['--verify', ref]);
32
+ case 4:
33
+ commit = _context.sent;
34
+ _context.next = 10;
35
+ break;
36
+ case 7:
37
+ _context.prev = 7;
38
+ _context.t0 = _context["catch"](1);
39
+ throw new ValidationError("Invalid git ref \"".concat(ref, "\""));
40
+ case 10:
41
+ _context.next = 12;
42
+ return git.diff([commit, '--', 'package.json']);
43
+ case 12:
44
+ diff = _context.sent;
45
+ modifiedPackages = diff.split('\n').map(parseDiffLine).filter(function (pkg) {
46
+ return Boolean(pkg);
47
+ });
48
+ addedPackages = new Map(modifiedPackages.filter(function (pkg) {
49
+ return pkg.type === 'added';
50
+ }).map(function (pkg) {
51
+ return [pkg.name, pkg];
52
+ }));
53
+ /* This is holds the previous version of packages that have been upgraded. Packages are treated as
54
+ * upgraded if they have both an addition/deletion entry in the diff and their versions differ
55
+ */
56
+ upgradedPackages = modifiedPackages.filter(function (pkg) {
57
+ var addedEntry = addedPackages.get(pkg.name);
58
+ if (pkg.type !== 'deleted' || !addedEntry) {
59
+ return false;
60
+ }
61
+ return pkg.version !== addedEntry.version;
62
+ }).map(function (_ref2) {
63
+ var name = _ref2.name,
64
+ version = _ref2.version;
65
+ return {
66
+ name: name,
67
+ version: version
68
+ };
69
+ });
70
+ return _context.abrupt("return", upgradedPackages);
71
+ case 17:
72
+ case "end":
73
+ return _context.stop();
76
74
  }
77
75
  }, _callee, null, [[1, 7]]);
78
76
  }));
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.11.5"
3
+ "version": "0.12.1"
4
4
  }
@@ -0,0 +1 @@
1
+ export declare function run(): Promise<void>;
@@ -0,0 +1,2 @@
1
+ /** Return products packages filePaths for running codemods from specified dependent package */
2
+ export declare function findDependentPackagePaths(crawlPaths: string[], dependencyPackage: string): Promise<string[]>;
@@ -0,0 +1,4 @@
1
+ export { default } from './main';
2
+ export type { UserFlags } from './main';
3
+ export { ValidationError, NoTransformsExistError } from './types';
4
+ export type { Flags } from './types';
@@ -0,0 +1,19 @@
1
+ import { Flags, Default } from './types';
2
+ declare const defaultFlags: {
3
+ parser: "babel";
4
+ extensions: string;
5
+ ignorePattern: string;
6
+ logger: Console;
7
+ };
8
+ export declare type UserFlags = Default<Flags, keyof typeof defaultFlags>;
9
+ export default function main(input: string[], userFlags: UserFlags): Promise<{
10
+ transforms: {
11
+ module: string;
12
+ root: string;
13
+ dir: string;
14
+ base: string;
15
+ ext: string;
16
+ name: string;
17
+ }[];
18
+ }>;
19
+ export {};
@@ -0,0 +1,2 @@
1
+ import { FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo): Promise<string>;
@@ -0,0 +1,3 @@
1
+ export declare const knownVariables: Record<string, string[]>;
2
+ export declare const knownColors: Record<string, string[]>;
3
+ export declare const knownRawColors: Record<string, string[]>;
@@ -0,0 +1 @@
1
+ export declare function cleanMeta(meta: string[]): string[];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Manually import presets to make sure typescript includes them
3
+ * in the final bundle
4
+ */
5
+ import './styled-to-emotion/styled-to-emotion';
6
+ import './theme-to-design-tokens/theme-to-design-tokens';
7
+ import './css-to-design-tokens/css-to-design-tokens';
8
+ declare const presets: string[];
9
+ export default presets;
@@ -0,0 +1,6 @@
1
+ import { FileInfo, API, Options } from 'jscodeshift';
2
+ /**
3
+ * Converts all imports of `styled-components` to `@emotion/styled`
4
+ */
5
+ export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options): string;
6
+ export declare const parser = "tsx";
@@ -0,0 +1,2 @@
1
+ import { API, FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, debug?: boolean): string;
@@ -0,0 +1,3 @@
1
+ import core from 'jscodeshift';
2
+ export declare function getMetaFromAncestors(j: core.JSCodeshift, path: any, meta?: string[]): string[];
3
+ export declare function cleanMeta(meta: string[]): string[];
@@ -0,0 +1,3 @@
1
+ import core from 'jscodeshift';
2
+ export declare function isDecendantOfToken(j: core.JSCodeshift, path: any): boolean;
3
+ export declare function isDecendantOfType(j: core.JSCodeshift, path: any, type: any): boolean;
@@ -0,0 +1,4 @@
1
+ export declare const isLegacyColor: (value: string) => boolean;
2
+ export declare const isLegacyNamedColor: (value: string) => boolean;
3
+ export declare const includesHardCodedColor: (raw: string) => boolean;
4
+ export declare const isHardCodedColor: (value: string) => boolean;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Fuzzy search ripped from the internet.
3
+ */
4
+ declare const FuzzySet: (arr?: string[], useLevenshtein?: boolean | undefined, gramSizeLower?: number, gramSizeUpper?: number) => any;
5
+ export default FuzzySet;
@@ -0,0 +1,3 @@
1
+ export declare const legacyColors: string[];
2
+ export declare const legacyColorMixins: string[];
3
+ export declare const legacyColorMetaMap: Record<string, string[]>;
@@ -0,0 +1 @@
1
+ export declare const namedColors: string[];
@@ -0,0 +1,2 @@
1
+ export declare const tokens: string[];
2
+ export declare const getUniqueWordsFromTokens: string[];
@@ -0,0 +1,5 @@
1
+ import { ParsedPkg } from './types';
2
+ /** Returns packages that have been upgraded in package.json since ref. The version refers to their previous
3
+ * version
4
+ */
5
+ export declare const getPackagesSinceRef: (ref: string) => Promise<ParsedPkg[]>;
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ import path, { ParsedPath } from 'path';
3
+ import { ParsedPkg } from './types';
4
+ export declare const hasTransform: (transformPath: string) => boolean;
5
+ /** Retrieves transforms for `packages` if provided, otherwise all transforms including presets */
6
+ export declare const getTransforms: (packages?: ParsedPkg[] | undefined) => ParsedPath[];
7
+ export declare const parseTransformPath: (transformPath: string) => path.ParsedPath;
8
+ export declare const getTransformPath: ({ dir, base }: ParsedPath) => string;
9
+ export declare const getTransformModule: (transform: ParsedPath) => string;
10
+ export declare const getTransformVersion: (transform: ParsedPath) => string;
@@ -0,0 +1,59 @@
1
+ import { FileInfo, API, Options } from 'jscodeshift';
2
+ export declare type Transform = (fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => string;
3
+ export declare type CliFlags = {
4
+ /**
5
+ * The transform to run
6
+ */
7
+ transform?: string;
8
+ /**
9
+ * select which transform to run
10
+ */
11
+ preset?: string;
12
+ /**
13
+ * Comma separated list of packages to run transforms for, @scope/package[@version]. If version is supplied, will only run transforms above that version
14
+ */
15
+ packages?: string;
16
+ /**
17
+ * Parser to use for parsing the source files
18
+ */
19
+ parser: 'babel' | 'babylon' | 'flow' | 'ts' | 'tsx';
20
+ /**
21
+ * Transform files with these file extensions (comma separated list)
22
+ */
23
+ extensions: string;
24
+ /**
25
+ * Ignore files that match a provided glob expression
26
+ */
27
+ ignorePattern: string;
28
+ /**
29
+ * Determines changed packages since the specified git ref and runs all codemods for them. The ref can be any valid git ref, e.g. a commit hash, HEAD etc.
30
+ */
31
+ sinceRef?: string;
32
+ /**
33
+ * Return a 1 exit code when errors were found during execution of codemods
34
+ */
35
+ failOnError?: boolean;
36
+ /**
37
+ * Filters source paths to package directories that declare a dependency on the package being upgraded
38
+ */
39
+ filterPaths?: boolean;
40
+ };
41
+ export declare type Flags = CliFlags & {
42
+ logger: {
43
+ log: (...args: any) => void;
44
+ warn: (...args: any) => void;
45
+ };
46
+ };
47
+ export declare type ParsedPkg = {
48
+ name: string;
49
+ version: string | null;
50
+ };
51
+ /** Converts required args to optional if they have a default
52
+ * Example: export type UserFlags = Default<Flags, keyof typeof defaultFlags>;
53
+ */
54
+ export declare type Default<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
55
+ export declare type ValidateShape<T, Shape> = T extends Shape ? Exclude<keyof T, keyof Shape> extends never ? T : never : never;
56
+ export declare class ValidationError extends Error {
57
+ }
58
+ export declare class NoTransformsExistError extends Error {
59
+ }
@@ -0,0 +1 @@
1
+ export declare const fixLineEnding: (source: string, lineEnding: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.11.5",
3
+ "version": "0.12.1",
4
4
  "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -24,7 +24,7 @@
24
24
  "codemod-cli": "./bin/codemod-cli.js"
25
25
  },
26
26
  "dependencies": {
27
- "@atlaskit/tokens": "^1.0.0",
27
+ "@atlaskit/tokens": "^1.3.0",
28
28
  "@babel/runtime": "^7.0.0",
29
29
  "@types/jscodeshift": "^0.11.0",
30
30
  "chalk": "^4.1.2",