forked from visgl/deck.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional types entry point (visgl#6946)
- Loading branch information
1 parent
d42c4e0
commit bc30a77
Showing
37 changed files
with
103 additions
and
24 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
dist/ | ||
dist-es6/ | ||
modules/*/typed | ||
node_modules/ | ||
workers/ | ||
dist.js | ||
|
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
build/ | ||
dist/ | ||
modules/*/typed | ||
**/*.min.js | ||
node_modules/ | ||
coverage/ | ||
|
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
workers/ | ||
**/dist*/**/* | ||
dist.js | ||
modules/*/typed | ||
*.min.js | ||
**/mapbox-gl-dev.js | ||
**/mapbox-gl.js | ||
|
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"files": [ | ||
"dist", | ||
"src", | ||
"typed", | ||
"dist.min.js" | ||
], | ||
"sideEffects": false, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"files": [ | ||
"dist", | ||
"src", | ||
"typed", | ||
"dist.min.js" | ||
], | ||
"sideEffects": false, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
"files": [ | ||
"dist", | ||
"src", | ||
"typed", | ||
"dist.min.js" | ||
], | ||
"sideEffects": false, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"files": [ | ||
"dist", | ||
"src", | ||
"typed", | ||
"debug.min.js", | ||
"dist.min.js" | ||
], | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"files": [ | ||
"dist", | ||
"src", | ||
"typed", | ||
"dist.min.js" | ||
], | ||
"sideEffects": false, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"files": [ | ||
"dist", | ||
"src", | ||
"typed", | ||
"dist.min.js" | ||
], | ||
"sideEffects": false, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"files": [ | ||
"dist", | ||
"src", | ||
"typed", | ||
"dist.min.js" | ||
], | ||
"sideEffects": false, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"files": [ | ||
"dist", | ||
"src", | ||
"typed", | ||
"dist.min.js" | ||
], | ||
"sideEffects": false, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
"files": [ | ||
"dist", | ||
"src", | ||
"typed", | ||
"dist.min.js" | ||
], | ||
"sideEffects": false, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
"files": [ | ||
"dist", | ||
"src", | ||
"typed", | ||
"dist.min.js" | ||
], | ||
"sideEffects": false, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"files": [ | ||
"dist", | ||
"src", | ||
"typed", | ||
"dist.min.js" | ||
], | ||
"sideEffects": false, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"files": [ | ||
"dist", | ||
"src", | ||
"typed", | ||
"dist.min.js" | ||
], | ||
"sideEffects": false, | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* This script enables a temporary, opt-in only entry point in each module while TypeScript is being developed. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const MODULES_DIR = path.resolve(__dirname, '../modules'); | ||
const IMPORT_PATTERN = /\bfrom ('|")(@deck.gl\/[\w\-]+)('|")/g; | ||
|
||
for (const moduleName of fs.readdirSync(MODULES_DIR)) { | ||
if (!isDirectory(`${MODULES_DIR}/${moduleName}`)) { | ||
continue; | ||
} | ||
|
||
const distDir = `${MODULES_DIR}/${moduleName}/typed`; | ||
if (isDirectory(distDir)) { | ||
// Create package.json | ||
const entryPoint = { | ||
internal: true, | ||
main: "../dist/es5/index.js", | ||
module: "../dist/esm/index.js", | ||
types: "index.d.ts" | ||
}; | ||
|
||
fs.writeFileSync(`${distDir}/package.json`, JSON.stringify(entryPoint, null, 2), 'utf8'); | ||
|
||
// Update all internal imports | ||
const stats = updateImports(distDir); | ||
console.log(`${stats.fileCount} files updated in module ${moduleName}`) | ||
|
||
} else { | ||
console.log(`No types found for module ${moduleName}`); | ||
} | ||
} | ||
|
||
function isDirectory(path) { | ||
try { | ||
const stats = fs.lstatSync(path); | ||
return stats.isDirectory(); | ||
} catch { | ||
// Does not exist | ||
return false; | ||
} | ||
} | ||
|
||
// Replace all internal imports (@deck.gl/*) with '@deck.gl/*/typed' | ||
function updateImports(path, stats = {fileCount: 0}) { | ||
for (const item of fs.readdirSync(path)) { | ||
const subPath = `${path}/${item}`; | ||
if (item.endsWith('.d.ts')) { | ||
// find imports | ||
let fileContent = fs.readFileSync(subPath, 'utf8'); | ||
if (IMPORT_PATTERN.test(fileContent)) { | ||
fileContent = fileContent.replace(IMPORT_PATTERN, (_, $1, $2) => `from '${$2}/typed'`); | ||
stats.fileCount++; | ||
fs.writeFileSync(subPath, fileContent, 'utf8'); | ||
} | ||
} else if (isDirectory(subPath)) { | ||
updateImports(subPath, stats); | ||
} | ||
} | ||
return stats; | ||
} |
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