-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: enforce naming in development * feat: add .map type to mimetypes * refactor: simplify obtaining sourcemaps * fix: getMimeType type * refactor: adjust getAsset type * feat: compiler plugin can serve local assets too * refactor: revert changes to externally available compiler plugin types * refactor: revert changes to compilerPlugin * refactor: dont alter filename in compilerPlugin * refactor: use inferPlatform for obtaining platform * refactor: remove redundant enforcement of sourcemap filename * refactor: naming * refactor: naming * refactor: cleanup * fix: handle missing platform in Compiler instead of compilerPlugin * chore: ignore dev-server type error for now * chore: add changeset * fix: align parseFileUrl after merge * refactor: extract getMimeType to common * refactor: align getSourceMap * fix: align changes for rspack * fix: align getSource for rspack * refactor: make the asset regex more maintainable * test: verify remote-assets are accessible in dev-server * test: verify source files are accessible in dev-server * test: add getMimeType tests * refactor: align return type to match mime-types lib * fix: include hot-update.json as well
- Loading branch information
Showing
14 changed files
with
154 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@callstack/repack': minor | ||
--- | ||
|
||
Enable dev-server to serve source assets alongside build artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,12 @@ describe('start command', () => { | |
'ios/src_asyncChunks_Async_local_tsx.chunk.bundle.map', | ||
'assets/src/miniapp/callstack-dark.png?platform=ios', | ||
`assets/${RELATIVE_REACT_NATIVE_PATH}/Libraries/NewAppScreen/components/logo.png?platform=ios`, | ||
`remote-assets/assets/src/assetsTest/remoteAssets/webpack.png?platform=ios`, | ||
`remote-assets/assets/src/assetsTest/remoteAssets/[email protected]?platform=ios`, | ||
`remote-assets/assets/src/assetsTest/remoteAssets/[email protected]?platform=ios`, | ||
`index.js`, | ||
`src/App.tsx`, | ||
`src/ui/undraw_Developer_activity_re_39tg.svg`, | ||
], | ||
}, | ||
{ | ||
|
@@ -74,6 +80,12 @@ describe('start command', () => { | |
'android/src_asyncChunks_Async_local_tsx.chunk.bundle.map', | ||
'assets/src/miniapp/callstack-dark.png?platform=android', | ||
`assets/${RELATIVE_REACT_NATIVE_PATH}/Libraries/NewAppScreen/components/logo.png?platform=android`, | ||
`remote-assets/assets/src/assetsTest/remoteAssets/webpack.png?platform=android`, | ||
`remote-assets/assets/src/assetsTest/remoteAssets/[email protected]?platform=android`, | ||
`remote-assets/assets/src/assetsTest/remoteAssets/[email protected]?platform=android`, | ||
`index.js`, | ||
`src/App.tsx`, | ||
`src/ui/undraw_Developer_activity_re_39tg.svg`, | ||
], | ||
}, | ||
])( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/repack/src/commands/common/__tests__/getMimeType.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getMimeType } from '../getMimeType'; | ||
|
||
describe('getMimeType', () => { | ||
it('should return correct MIME types for various file extensions', () => { | ||
expect(getMimeType('script.js')).toBe('application/javascript'); | ||
expect(getMimeType('main.bundle')).toBe('application/javascript'); | ||
expect(getMimeType('main.bundle.map')).toBe('application/json'); | ||
expect(getMimeType('hot-update.js')).toBe('application/javascript'); | ||
expect(getMimeType('image.png')).toBe('image/png'); | ||
expect(getMimeType('unknownfile.unknown')).toBe('text/plain'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import mimeTypes from 'mime-types'; | ||
|
||
/** | ||
* Get the MIME type for a given filename. | ||
* | ||
* Note: The `mime-types` library currently uses 'application/javascript' for JavaScript files, | ||
* but 'text/javascript' is more widely recognized and standard. | ||
* | ||
* @param {string} filename - The name of the file to get the MIME type for. | ||
* @returns {string} - The MIME type of the file. | ||
*/ | ||
export function getMimeType(filename: string) { | ||
if (filename.endsWith('.bundle')) { | ||
return 'application/javascript'; | ||
} | ||
|
||
if (filename.endsWith('.map')) { | ||
return 'application/json'; | ||
} | ||
|
||
return mimeTypes.lookup(filename) || 'text/plain'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.