unframer 2.7.6 → 2.7.8

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 (78) hide show
  1. package/README.md +5 -6
  2. package/dist/babel-plugin-imports.d.ts +21 -0
  3. package/dist/babel-plugin-imports.d.ts.map +1 -0
  4. package/dist/babel-plugin-imports.js +375 -0
  5. package/dist/babel-plugin-imports.js.map +1 -0
  6. package/dist/cli.d.ts +14 -0
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +9 -42
  9. package/dist/cli.js.map +1 -1
  10. package/dist/css.d.ts.map +1 -1
  11. package/dist/css.js +4 -3
  12. package/dist/css.js.map +1 -1
  13. package/dist/esbuild.d.ts +7 -0
  14. package/dist/esbuild.d.ts.map +1 -1
  15. package/dist/esbuild.js +15 -1
  16. package/dist/esbuild.js.map +1 -1
  17. package/dist/exporter.d.ts +6 -14
  18. package/dist/exporter.d.ts.map +1 -1
  19. package/dist/exporter.js +79 -38
  20. package/dist/exporter.js.map +1 -1
  21. package/dist/exporter.test.js +48 -0
  22. package/dist/exporter.test.js.map +1 -1
  23. package/dist/framer.d.ts.map +1 -1
  24. package/dist/framer.js +26 -1788
  25. package/dist/framer.js.map +1 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/renamer.d.ts +12 -0
  29. package/dist/renamer.d.ts.map +1 -0
  30. package/dist/renamer.js +169 -0
  31. package/dist/renamer.js.map +1 -0
  32. package/dist/unframer-loader.d.ts.map +1 -1
  33. package/dist/unframer-loader.js +4 -3
  34. package/dist/unframer-loader.js.map +1 -1
  35. package/esm/babel-plugin-imports.d.ts +21 -0
  36. package/esm/babel-plugin-imports.d.ts.map +1 -0
  37. package/esm/babel-plugin-imports.js +344 -0
  38. package/esm/babel-plugin-imports.js.map +1 -0
  39. package/esm/cli.d.ts +14 -0
  40. package/esm/cli.d.ts.map +1 -1
  41. package/esm/cli.js +9 -42
  42. package/esm/cli.js.map +1 -1
  43. package/esm/css.d.ts.map +1 -1
  44. package/esm/css.js +3 -2
  45. package/esm/css.js.map +1 -1
  46. package/esm/esbuild.d.ts +7 -0
  47. package/esm/esbuild.d.ts.map +1 -1
  48. package/esm/esbuild.js +13 -0
  49. package/esm/esbuild.js.map +1 -1
  50. package/esm/exporter.d.ts +6 -14
  51. package/esm/exporter.d.ts.map +1 -1
  52. package/esm/exporter.js +78 -37
  53. package/esm/exporter.js.map +1 -1
  54. package/esm/exporter.test.js +48 -0
  55. package/esm/exporter.test.js.map +1 -1
  56. package/esm/framer.d.ts.map +1 -1
  57. package/esm/framer.js +27 -1788
  58. package/esm/framer.js.map +1 -1
  59. package/esm/index.d.ts.map +1 -1
  60. package/esm/index.js.map +1 -1
  61. package/esm/renamer.d.ts +12 -0
  62. package/esm/renamer.d.ts.map +1 -0
  63. package/esm/renamer.js +140 -0
  64. package/esm/renamer.js.map +1 -0
  65. package/esm/unframer-loader.d.ts.map +1 -1
  66. package/esm/unframer-loader.js +4 -3
  67. package/esm/unframer-loader.js.map +1 -1
  68. package/package.json +6 -4
  69. package/src/babel-plugin-imports.ts +441 -0
  70. package/src/cli.tsx +11 -52
  71. package/src/css.ts +3 -2
  72. package/src/esbuild.ts +24 -2
  73. package/src/exporter.test.ts +66 -0
  74. package/src/exporter.ts +95 -42
  75. package/src/framer.js +25 -1827
  76. package/src/index.ts +2 -0
  77. package/src/renamer.ts +184 -0
  78. package/src/unframer-loader.ts +7 -3
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './framer.js'
2
+
3
+
2
4
  export {
3
5
  FramerStyles,
4
6
  UnframerBreakpoint,
package/src/renamer.ts ADDED
@@ -0,0 +1,184 @@
1
+ // original https://github.com/babel/babel/blob/9c77558234c87b9220604fbc1519089e2d6334e2/packages/babel-traverse/src/scope/lib/renamer.ts#L61
2
+ import splitExportDeclaration from '@babel/helper-split-export-declaration'
3
+ import type { Scope } from '@babel/traverse'
4
+ import { visitors } from '@babel/traverse'
5
+ import { traverseNode } from '@babel/traverse/lib/traverse-node'
6
+
7
+ import * as t from '@babel/types'
8
+
9
+ import { NodePath, Visitor } from '@babel/core'
10
+ import type { Identifier } from '@babel/types'
11
+ import { logger } from './utils'
12
+
13
+ const renameVisitor: Visitor<BatchRenamer> = {
14
+ ReferencedIdentifier({ node }, state) {
15
+ for (let [oldName, newName] of state.map) {
16
+ // console.log(node.name, oldName, newName)
17
+ if (node.name === oldName) {
18
+ node.name = newName
19
+ }
20
+ }
21
+ },
22
+
23
+ // Scope(path, state) {
24
+ // if (
25
+ // !path.scope.bindingIdentifierEquals(
26
+ // state.oldName,
27
+ // state.binding.identifier,
28
+ // )
29
+ // ) {
30
+ // path.skip()
31
+ // if (path.isMethod()) {
32
+ // requeueComputedKeyAndDecorators(path)
33
+ // }
34
+ // }
35
+ // },
36
+
37
+ ObjectProperty({ node, scope }, state) {
38
+ const { name } = node.key as Identifier
39
+ if (
40
+ node.shorthand &&
41
+ // In destructuring the identifier is already renamed by the
42
+ // AssignmentExpression|Declaration|VariableDeclarator visitor,
43
+ // while in object literals it's renamed later by the
44
+ // ReferencedIdentifier visitor.
45
+ // (name === state.oldName || name === state.newName) &&
46
+ (state.map.has(name) || inverseMap(state.map).has(name)) &&
47
+ // Ignore shadowed bindings
48
+ [...state.map.keys()].some(
49
+ (oldName) =>
50
+ state.scope.getBindingIdentifier(oldName) ===
51
+ scope.getBindingIdentifier(name),
52
+ )
53
+ ) {
54
+ node.shorthand = false
55
+ if (node.extra?.shorthand) node.extra.shorthand = false
56
+ }
57
+ },
58
+
59
+ // @ts-ignore
60
+ 'AssignmentExpression|Declaration|VariableDeclarator'(
61
+ path: NodePath<
62
+ t.AssignmentPattern | t.Declaration | t.VariableDeclarator
63
+ >,
64
+ state,
65
+ ) {
66
+ if (path.isVariableDeclaration()) return
67
+ const ids = path.getOuterBindingIdentifiers()
68
+
69
+ for (const name in ids) {
70
+ for (let [oldName, newName] of state.map) {
71
+ // console.log(name, oldName, newName)
72
+ if (name === oldName) ids[name].name = newName
73
+ }
74
+ }
75
+ },
76
+ }
77
+
78
+ let cache = new WeakMap()
79
+ function inverseMap(map: Map<string, string>) {
80
+ if (cache.has(map)) return cache.get(map)
81
+ const inverse = new Map()
82
+ for (let [key, value] of map) {
83
+ inverse.set(value, key)
84
+ }
85
+ cache.set(map, inverse)
86
+ return inverse
87
+ }
88
+
89
+ export default class BatchRenamer {
90
+ constructor(scope: Scope, map: Map<string, string>) {
91
+ this.map = map
92
+ this.scope = scope
93
+ }
94
+
95
+ declare map: Map<string, string>
96
+
97
+ declare scope: Scope
98
+
99
+ maybeConvertFromExportDeclaration(parentDeclar: NodePath) {
100
+ const maybeExportDeclar = parentDeclar.parentPath
101
+
102
+ if (!maybeExportDeclar?.isExportDeclaration()) {
103
+ return
104
+ }
105
+
106
+ if (maybeExportDeclar.isExportDefaultDeclaration()) {
107
+ const { declaration } = maybeExportDeclar.node
108
+ if (t.isDeclaration(declaration) && !declaration.id) {
109
+ return
110
+ }
111
+ }
112
+
113
+ if (maybeExportDeclar.isExportAllDeclaration()) {
114
+ return
115
+ }
116
+
117
+ splitExportDeclaration(
118
+ maybeExportDeclar as NodePath<
119
+ Exclude<t.ExportDeclaration, t.ExportAllDeclaration>
120
+ >,
121
+ )
122
+ }
123
+
124
+ maybeConvertFromClassFunctionExpression(path: NodePath) {
125
+ return path
126
+ }
127
+
128
+ rename(/* Babel 7 - block?: t.Pattern | t.Scopable */) {
129
+ const { scope, map } = this
130
+
131
+ for (let binding of [...map.keys()].map((name) =>
132
+ scope.getBinding(name),
133
+ )) {
134
+ if (!binding) {
135
+ continue
136
+ }
137
+ const path = binding!.path
138
+ const parentDeclar = path.find(
139
+ (path) =>
140
+ path.isDeclaration() ||
141
+ path.isFunctionExpression() ||
142
+ path.isClassExpression(),
143
+ )
144
+ if (parentDeclar) {
145
+ const bindingIds = parentDeclar.getOuterBindingIdentifiers()
146
+ const oldNames = Object.keys(bindingIds)
147
+ for (let oldName of oldNames) {
148
+ const binding = scope.getBinding(oldName)
149
+ if (binding && bindingIds[oldName] === binding.identifier) {
150
+ // When we are renaming an exported identifier, we need to ensure that
151
+ // the exported binding keeps the old name.
152
+ this.maybeConvertFromExportDeclaration(parentDeclar)
153
+ }
154
+ }
155
+ }
156
+ }
157
+
158
+ traverseNode(
159
+ scope.block,
160
+ visitors.explode(renameVisitor),
161
+ scope,
162
+ this,
163
+ scope.path,
164
+ // When blockToTraverse is a SwitchStatement, the discriminant
165
+ // is not part of the current scope and thus should be skipped.
166
+ { discriminant: true },
167
+ )
168
+
169
+ for (let [oldName, newName] of map) {
170
+ if (oldName === newName) continue
171
+
172
+ if (!arguments[0]) {
173
+ scope.removeOwnBinding(oldName)
174
+ const binding = scope.getBinding(oldName)
175
+ if (binding) {
176
+ binding.identifier.name = newName
177
+ scope.bindings[newName] = binding
178
+ } else {
179
+ logger.log(`binding not found for ${oldName}`)
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
@@ -1,10 +1,14 @@
1
+ const mapPackages = JSON.parse(process.env.UNFRAMER_MAP_PACKAGES || '{}')
2
+
1
3
  export async function resolve(specifier, context, defaultResolve) {
2
- if (specifier === 'unframer') {
4
+ if (mapPackages[specifier]) {
3
5
  return {
4
- url: process.env.UNFRAMER_RUNTIME_PATH,
5
- format: 'module', // Specify that unframer is an ES module
6
+ url: mapPackages[specifier],
7
+ // format: 'module', // Specify that unframer is an ES module
6
8
  shortCircuit: true, // Signal that we're intentionally not calling next hook
7
9
  }
8
10
  }
11
+
12
+
9
13
  return defaultResolve(specifier, context, defaultResolve)
10
14
  }