@remix-run/assets 0.1.0 → 0.3.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 (72) hide show
  1. package/README.md +88 -67
  2. package/dist/lib/access.d.ts.map +1 -1
  3. package/dist/lib/access.js +3 -0
  4. package/dist/lib/asset-server.d.ts +50 -45
  5. package/dist/lib/asset-server.d.ts.map +1 -1
  6. package/dist/lib/asset-server.js +159 -50
  7. package/dist/lib/compilation-error.d.ts +2 -2
  8. package/dist/lib/compilation-error.d.ts.map +1 -1
  9. package/dist/lib/compilation-error.js +1 -1
  10. package/dist/lib/file-matcher.d.ts.map +1 -1
  11. package/dist/lib/file-matcher.js +3 -2
  12. package/dist/lib/injected-packages.d.ts +11 -0
  13. package/dist/lib/injected-packages.d.ts.map +1 -0
  14. package/dist/lib/injected-packages.js +86 -0
  15. package/dist/lib/module-store.d.ts +41 -0
  16. package/dist/lib/module-store.d.ts.map +1 -0
  17. package/dist/lib/{scripts/store.js → module-store.js} +43 -41
  18. package/dist/lib/paths.d.ts +1 -0
  19. package/dist/lib/paths.d.ts.map +1 -1
  20. package/dist/lib/paths.js +12 -0
  21. package/dist/lib/routes.d.ts +5 -7
  22. package/dist/lib/routes.d.ts.map +1 -1
  23. package/dist/lib/routes.js +13 -16
  24. package/dist/lib/scripts/compiler.d.ts +15 -15
  25. package/dist/lib/scripts/compiler.d.ts.map +1 -1
  26. package/dist/lib/scripts/compiler.js +50 -46
  27. package/dist/lib/scripts/emit.js +2 -2
  28. package/dist/lib/scripts/resolve.d.ts +7 -17
  29. package/dist/lib/scripts/resolve.d.ts.map +1 -1
  30. package/dist/lib/scripts/resolve.js +47 -14
  31. package/dist/lib/scripts/transform.d.ts +11 -9
  32. package/dist/lib/scripts/transform.d.ts.map +1 -1
  33. package/dist/lib/scripts/transform.js +110 -23
  34. package/dist/lib/source-maps.d.ts +1 -1
  35. package/dist/lib/source-maps.d.ts.map +1 -1
  36. package/dist/lib/source-maps.js +7 -1
  37. package/dist/lib/styles/compiler.d.ts +52 -0
  38. package/dist/lib/styles/compiler.d.ts.map +1 -0
  39. package/dist/lib/styles/compiler.js +272 -0
  40. package/dist/lib/styles/emit.d.ts +25 -0
  41. package/dist/lib/styles/emit.d.ts.map +1 -0
  42. package/dist/lib/styles/emit.js +78 -0
  43. package/dist/lib/styles/resolve.d.ts +48 -0
  44. package/dist/lib/styles/resolve.d.ts.map +1 -0
  45. package/dist/lib/styles/resolve.js +188 -0
  46. package/dist/lib/styles/transform.d.ts +47 -0
  47. package/dist/lib/styles/transform.d.ts.map +1 -0
  48. package/dist/lib/styles/transform.js +131 -0
  49. package/dist/lib/target.d.ts +21 -0
  50. package/dist/lib/target.d.ts.map +1 -0
  51. package/dist/lib/target.js +127 -0
  52. package/package.json +13 -4
  53. package/src/lib/access.ts +2 -0
  54. package/src/lib/asset-server.ts +239 -99
  55. package/src/lib/compilation-error.ts +7 -7
  56. package/src/lib/file-matcher.ts +3 -2
  57. package/src/lib/injected-packages.ts +117 -0
  58. package/src/lib/{scripts/store.ts → module-store.ts} +100 -87
  59. package/src/lib/paths.ts +28 -0
  60. package/src/lib/routes.ts +31 -22
  61. package/src/lib/scripts/compiler.ts +88 -70
  62. package/src/lib/scripts/emit.ts +2 -2
  63. package/src/lib/scripts/resolve.ts +85 -28
  64. package/src/lib/scripts/transform.ts +153 -36
  65. package/src/lib/source-maps.ts +8 -1
  66. package/src/lib/styles/compiler.ts +400 -0
  67. package/src/lib/styles/emit.ts +137 -0
  68. package/src/lib/styles/resolve.ts +316 -0
  69. package/src/lib/styles/transform.ts +226 -0
  70. package/src/lib/target.ts +196 -0
  71. package/dist/lib/scripts/store.d.ts +0 -40
  72. package/dist/lib/scripts/store.d.ts.map +0 -1
@@ -0,0 +1,196 @@
1
+ import type { Targets as LightningCssTargets } from 'lightningcss'
2
+
3
+ const browserTargetNames = [
4
+ 'chrome',
5
+ 'edge',
6
+ 'firefox',
7
+ 'ie',
8
+ 'ios',
9
+ 'opera',
10
+ 'safari',
11
+ 'samsung',
12
+ ] as const
13
+
14
+ const browserTargetNameSet = new Set<string>(browserTargetNames)
15
+
16
+ const lightningCssTargetNameByBrowserTargetName = {
17
+ chrome: 'chrome',
18
+ edge: 'edge',
19
+ firefox: 'firefox',
20
+ ie: 'ie',
21
+ ios: 'ios_saf',
22
+ opera: 'opera',
23
+ safari: 'safari',
24
+ samsung: 'samsung',
25
+ } as const satisfies Record<BrowserTargetName, keyof LightningCssTargets>
26
+
27
+ export type AssetTargetVersion =
28
+ | `${number}`
29
+ | `${number}.${number}`
30
+ | `${number}.${number}.${number}`
31
+ export type BrowserTargetName = (typeof browserTargetNames)[number]
32
+ export type ResolvedScriptTarget = string[]
33
+ export type ResolvedStyleTarget = LightningCssTargets
34
+
35
+ export interface AssetTarget {
36
+ chrome?: AssetTargetVersion
37
+ edge?: AssetTargetVersion
38
+ firefox?: AssetTargetVersion
39
+ ie?: AssetTargetVersion
40
+ ios?: AssetTargetVersion
41
+ opera?: AssetTargetVersion
42
+ safari?: AssetTargetVersion
43
+ samsung?: AssetTargetVersion
44
+ es?: string
45
+ }
46
+
47
+ type NormalizedAssetTarget = Partial<Record<BrowserTargetName, AssetTargetVersion>> & {
48
+ es?: AssetTarget['es']
49
+ }
50
+
51
+ export function resolveScriptTarget(
52
+ target: AssetTarget | undefined,
53
+ ): ResolvedScriptTarget | undefined {
54
+ let resolvedTarget = normalizeScriptTargetObject(target, 'target')
55
+ if (!resolvedTarget) return undefined
56
+
57
+ let oxcTarget: ResolvedScriptTarget = []
58
+ if (resolvedTarget.es) {
59
+ oxcTarget.push(resolvedTarget.es)
60
+ }
61
+
62
+ for (let browserTargetName of browserTargetNames) {
63
+ let version = resolvedTarget[browserTargetName]
64
+ if (version == null) continue
65
+ oxcTarget.push(`${browserTargetName}${version}`)
66
+ }
67
+
68
+ return oxcTarget
69
+ }
70
+
71
+ export function resolveStyleTarget(
72
+ target: AssetTarget | undefined,
73
+ ): ResolvedStyleTarget | undefined {
74
+ let resolvedTarget = normalizeStyleTargetObject(target, 'target')
75
+ if (!resolvedTarget) return undefined
76
+
77
+ let lightningCssTargets: ResolvedStyleTarget = {}
78
+ for (let browserTargetName of browserTargetNames) {
79
+ let version = resolvedTarget[browserTargetName]
80
+ if (version == null) continue
81
+ lightningCssTargets[lightningCssTargetNameByBrowserTargetName[browserTargetName]] =
82
+ toLightningCssTargetVersion(version)
83
+ }
84
+
85
+ return lightningCssTargets
86
+ }
87
+
88
+ function normalizeScriptTargetObject(
89
+ target: AssetTarget | undefined,
90
+ optionPath: string,
91
+ ): NormalizedAssetTarget | undefined {
92
+ if (target == null) return undefined
93
+ if (!isPlainObject(target)) {
94
+ throw new TypeError(`${optionPath} must be an object`)
95
+ }
96
+
97
+ let normalizedTarget: NormalizedAssetTarget = {}
98
+
99
+ for (let [key, value] of Object.entries(target)) {
100
+ if (key === 'es') {
101
+ normalizedTarget.es = normalizeScriptTargetVersion(value, `${optionPath}.es`)
102
+ continue
103
+ }
104
+
105
+ if (!browserTargetNameSet.has(key)) {
106
+ throw new TypeError(`${optionPath}.${key} is not a supported target`)
107
+ }
108
+
109
+ normalizedTarget[key as BrowserTargetName] = normalizeBrowserTargetVersion(
110
+ value,
111
+ `${optionPath}.${key}`,
112
+ )
113
+ }
114
+
115
+ return Object.keys(normalizedTarget).length === 0 ? undefined : normalizedTarget
116
+ }
117
+
118
+ function normalizeStyleTargetObject(
119
+ target: AssetTarget | undefined,
120
+ optionPath: string,
121
+ ): NormalizedAssetTarget | undefined {
122
+ if (target == null) return undefined
123
+ if (!isPlainObject(target)) {
124
+ throw new TypeError(`${optionPath} must be an object`)
125
+ }
126
+
127
+ let normalizedTarget: NormalizedAssetTarget = {}
128
+
129
+ for (let [key, value] of Object.entries(target)) {
130
+ if (key === 'es') {
131
+ continue
132
+ }
133
+
134
+ if (!browserTargetNameSet.has(key)) {
135
+ throw new TypeError(`${optionPath}.${key} is not a supported target`)
136
+ }
137
+
138
+ normalizedTarget[key as BrowserTargetName] = normalizeBrowserTargetVersion(
139
+ value,
140
+ `${optionPath}.${key}`,
141
+ )
142
+ }
143
+
144
+ return Object.keys(normalizedTarget).length === 0 ? undefined : normalizedTarget
145
+ }
146
+
147
+ function normalizeScriptTargetVersion(value: unknown, optionPath: string): AssetTarget['es'] {
148
+ if (typeof value !== 'string') {
149
+ throw new TypeError(`${optionPath} must be a string`)
150
+ }
151
+
152
+ let normalizedValue = value.trim()
153
+ if (normalizedValue.length === 0) {
154
+ throw new TypeError(`${optionPath} must be a non-empty string`)
155
+ }
156
+
157
+ if (!/^\d+$/.test(normalizedValue)) {
158
+ throw new TypeError(`${optionPath} must use a single numeric year like "2020"`)
159
+ }
160
+
161
+ if (!/^\d{4}$/.test(normalizedValue) || Number(normalizedValue) < 2015) {
162
+ throw new TypeError(`${optionPath} must use a four-digit year of 2015 or higher`)
163
+ }
164
+
165
+ return `es${normalizedValue}`
166
+ }
167
+
168
+ function normalizeBrowserTargetVersion(value: unknown, optionPath: string): AssetTargetVersion {
169
+ if (typeof value !== 'string') {
170
+ throw new TypeError(`${optionPath} must be a string`)
171
+ }
172
+
173
+ if (value.trim().length === 0) {
174
+ throw new TypeError(`${optionPath} must be a non-empty string`)
175
+ }
176
+
177
+ if (!/^\d+(\.\d+){0,2}$/.test(value)) {
178
+ throw new TypeError(`${optionPath} must use "X", "X.Y", or "X.Y.Z" version format`)
179
+ }
180
+
181
+ let segments = value.split('.').map(Number)
182
+ if (segments.some((segment) => segment > 255)) {
183
+ throw new TypeError(`${optionPath} must use version components between 0 and 255`)
184
+ }
185
+
186
+ return value as AssetTargetVersion
187
+ }
188
+
189
+ function toLightningCssTargetVersion(version: AssetTargetVersion): number {
190
+ let [major, minor = 0, patch = 0] = version.split('.').map(Number)
191
+ return major * 65536 + minor * 256 + patch
192
+ }
193
+
194
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
195
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
196
+ }
@@ -1,40 +0,0 @@
1
- import type { EmittedModule } from './emit.ts';
2
- import type { ResolutionFailureState, ResolvedModule, TrackedResolution } from './resolve.ts';
3
- import type { TransformFailureState, TransformedModule } from './transform.ts';
4
- export type ModuleWatchEvent = 'change' | 'add' | 'unlink';
5
- export type FileSnapshot = {
6
- mtimeNs: bigint;
7
- size: bigint;
8
- };
9
- export type ModuleSnapshot = ReadonlyMap<string, FileSnapshot>;
10
- type ModuleRecordState = {
11
- identityPath: string;
12
- invalidationVersion: number;
13
- transformed?: TransformedModule;
14
- resolved?: ResolvedModule;
15
- emitted?: EmittedModule;
16
- emittedSnapshot?: ModuleSnapshot;
17
- staleEmitted?: EmittedModule;
18
- staleEmittedSnapshot?: ModuleSnapshot;
19
- trackedFiles: ReadonlySet<string>;
20
- trackedResolutions: readonly TrackedResolution[];
21
- };
22
- export type ModuleRecord = Readonly<ModuleRecordState>;
23
- type ModuleStore = {
24
- get(identityPath: string): ModuleRecord;
25
- setTransformFailure(identityPath: string, failure: TransformFailureState): void;
26
- setTransformed(identityPath: string, transformed: TransformedModule): void;
27
- setResolved(identityPath: string, resolved: ResolvedModule): void;
28
- setResolveFailure(identityPath: string, failure: ResolutionFailureState): void;
29
- setEmitted(identityPath: string, emitted: EmittedModule, snapshot: ModuleSnapshot | null): void;
30
- invalidateForFileEvent(filePath: string, event: ModuleWatchEvent): void;
31
- invalidateAll(): void;
32
- };
33
- export declare function createModuleStore(options?: {
34
- onWatchDirectoriesChange?: (delta: {
35
- add: string[];
36
- remove: string[];
37
- }) => void;
38
- }): ModuleStore;
39
- export {};
40
- //# sourceMappingURL=store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/lib/scripts/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAE9C,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAC7F,OAAO,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