-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added @atlassian/atlaspack package which unifies
entire project
- Loading branch information
Showing
23 changed files
with
726 additions
and
15 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
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,7 @@ | ||
/* | ||
!index.js | ||
!index.d.ts | ||
!.scripts | ||
!package.json | ||
!.gitignore | ||
!.npmignore |
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,6 @@ | ||
!* | ||
.scripts | ||
.gitignore | ||
.npmignore | ||
node_modules | ||
*.tgz |
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,80 @@ | ||
import * as fs from 'node:fs'; | ||
import glob from 'glob'; | ||
import {Paths} from './paths.ts'; | ||
import {readJson, remapImports, rm, writeJson} from './fs.ts'; | ||
import {buildCore} from './build_core.ts'; | ||
import {buildPlugins} from './build_plugin.ts'; | ||
import {gatherDependencies, gatherDevDependencies} from './gather_deps.ts'; | ||
|
||
const whitelist = [ | ||
'.scripts', | ||
'.gitignore', | ||
'.npmignore', | ||
'index.d.ts', | ||
'index.js', | ||
'package.json', | ||
]; | ||
|
||
void (async function main() { | ||
// Clean dir | ||
for (const target of fs.readdirSync(Paths['~/']())) { | ||
if (whitelist.includes(target)) continue; | ||
await rm(Paths['~/'](target as string)); | ||
} | ||
|
||
await buildCore(); | ||
await buildPlugins(); | ||
|
||
await remapImports( | ||
...glob.sync(Paths['~/']('**/*.ts'), {ignore: '.scripts'}), | ||
...glob.sync(Paths['~/']('**/*.js'), {ignore: '.scripts'}), | ||
...glob.sync(Paths['~/']('**/*.json'), {ignore: '.scripts'}), | ||
); | ||
|
||
const pkg = await readJson(Paths['~/']('package.json')); | ||
pkg.dependencies = { | ||
...(await gatherDependencies( | ||
Paths['root/']('packages/core/diagnostic/package.json'), | ||
Paths['root/']('packages/core/feature-flags/package.json'), | ||
Paths['root/']('packages/core/utils/package.json'), | ||
Paths['root/']('packages/core/logger/package.json'), | ||
Paths['root/']('packages/core/types-internal/package.json'), | ||
Paths['root/']('packages/core/markdown-ansi/package.json'), | ||
Paths['root/']('packages/core/profiler/package.json'), | ||
Paths['root/']('packages/core/build-cache/package.json'), | ||
Paths['root/']('packages/core/build-cache/package.json'), | ||
Paths['root/']( | ||
'packages/utils/atlaspack-watcher-watchman-js/package.json', | ||
), | ||
Paths['root/']('packages/core/workers/package.json'), | ||
Paths['root/']('packages/core/types/package.json'), | ||
Paths['root/']('packages/core/fs/package.json'), | ||
Paths['root/']('packages/utils/domain-sharding/package.json'), | ||
Paths['root/']('packages/utils/ts-utils/package.json'), | ||
Paths['root/']('packages/core/plugin/package.json'), | ||
Paths['root/']('packages/utils/node-resolver-core/package.json'), | ||
Paths['root/']('packages/core/cache/package.json'), | ||
Paths['root/']('packages/core/graph/package.json'), | ||
Paths['root/']('packages/core/package-manager/package.json'), | ||
Paths['root/']('packages/core/core/package.json'), | ||
Paths['root/']('packages/core/cli/package.json'), | ||
...glob.sync(Paths['root/']('packages/bundlers/**/package.json')), | ||
...glob.sync(Paths['root/']('packages/compressors/**/package.json')), | ||
...glob.sync(Paths['root/']('packages/namers/**/package.json')), | ||
...glob.sync(Paths['root/']('packages/optimizers/**/package.json')), | ||
...glob.sync(Paths['root/']('packages/packagers/**/package.json')), | ||
...glob.sync(Paths['root/']('packages/reporters/**/package.json')), | ||
...glob.sync(Paths['root/']('packages/resolvers/**/package.json')), | ||
...glob.sync(Paths['root/']('packages/runtimes/**/package.json')), | ||
...glob.sync(Paths['root/']('packages/transformers/**/package.json')), | ||
...glob.sync(Paths['root/']('packages/validators/**/package.json')), | ||
)), | ||
}; | ||
pkg.devDependencies = { | ||
...(await gatherDevDependencies( | ||
Paths['root/']('packages/utils/node-resolver-core/package.json'), | ||
)), | ||
}; | ||
|
||
await writeJson(Paths['~/']('package.json'), pkg); | ||
})(); |
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,185 @@ | ||
import * as fs from 'node:fs'; | ||
import glob from 'glob'; | ||
import {Paths} from './paths.ts'; | ||
import {writeFile, cp} from './fs.ts'; | ||
import {gatherDependencies} from './gather_deps.ts'; | ||
|
||
export async function buildCore() { | ||
// packages/core/diagnostic | ||
await cp( | ||
Paths['root/']('packages/core/diagnostic/lib'), | ||
Paths['~/']('diagnostic'), | ||
); | ||
await writeFile( | ||
Paths['~/']('diagnostic/index.js'), | ||
'module.exports = require("./diagnostic.js")', | ||
); | ||
await writeFile( | ||
Paths['~/']('diagnostic/index.d.ts'), | ||
'export * from "./diagnostic"', | ||
); | ||
|
||
// packages/core/feature-flags | ||
await cp( | ||
Paths['root/']('packages/core/feature-flags/lib'), | ||
Paths['~/']('feature-flags'), | ||
); | ||
await writeFile( | ||
Paths['~/']('feature-flags/index.d.ts'), | ||
'export * from "./types"', | ||
); | ||
|
||
// packages/utils/events | ||
await cp(Paths['root/']('packages/utils/events/lib'), Paths['~/']('events')); | ||
|
||
// packages/core/rust | ||
for (const match of [ | ||
Paths['root/']('packages/core/rust/index.js'), | ||
Paths['root/']('packages/core/rust/index.d.ts'), | ||
Paths['root/']('packages/core/rust/browser.js'), | ||
...glob.sync(Paths['root/']('packages/core/rust/*.node')), | ||
...glob.sync(Paths['root/']('packages/core/rust/*.wasm')), | ||
]) { | ||
let trimmed = match.replace(Paths['root/']('packages/core/rust'), ''); | ||
await cp(match, Paths['~/']('rust', trimmed)); | ||
} | ||
|
||
// packages/core/logger | ||
await cp(Paths['root/']('packages/core/logger/lib'), Paths['~/']('logger')); | ||
await writeFile( | ||
Paths['~/']('logger/index.js'), | ||
'module.exports = require("./Logger.js")', | ||
); | ||
await writeFile(Paths['~/']('logger/index.d.ts'), 'export * from "./Logger"'); | ||
|
||
// packages/core/types-internal | ||
await cp( | ||
Paths['root/']('packages/core/types-internal/lib'), | ||
Paths['~/']('types-internal'), | ||
); | ||
await writeFile( | ||
Paths['~/']('types-internal/index.js'), | ||
'module.exports = {}\n', | ||
); | ||
|
||
// packages/core/codeframe | ||
await cp( | ||
Paths['root/']('packages/core/codeframe/lib'), | ||
Paths['~/']('codeframe'), | ||
); | ||
await writeFile( | ||
Paths['~/']('codeframe/index.js'), | ||
'module.exports = require("./codeframe.js")', | ||
); | ||
|
||
// packages/core/markdown-ansi | ||
await cp( | ||
Paths['root/']('packages/core/markdown-ansi/lib'), | ||
Paths['~/']('markdown-ansi'), | ||
); | ||
await writeFile( | ||
Paths['~/']('markdown-ansi/index.js'), | ||
'module.exports = require("./markdown-ansi.js")', | ||
); | ||
|
||
// packages/core/utils | ||
await cp(Paths['root/']('packages/core/utils/lib'), Paths['~/']('utils')); | ||
|
||
// packages/core/profiler | ||
await cp( | ||
Paths['root/']('packages/core/profiler/lib'), | ||
Paths['~/']('profiler'), | ||
); | ||
|
||
// packages/core/build-cache | ||
await cp( | ||
Paths['root/']('packages/core/build-cache/lib'), | ||
Paths['~/']('build-cache'), | ||
); | ||
|
||
// packages/utils/atlaspack-watcher-watchman-js | ||
await cp( | ||
Paths['root/']('packages/utils/atlaspack-watcher-watchman-js/lib'), | ||
Paths['~/']('atlaspack-watcher-watchman-js'), | ||
); | ||
|
||
// packages/core/workers | ||
await cp(Paths['root/']('packages/core/workers/lib'), Paths['~/']('workers')); | ||
|
||
// packages/core/types | ||
await cp(Paths['root/']('packages/core/types/lib'), Paths['~/']('types')); | ||
await writeFile(Paths['~/']('types/index.js'), 'module.exports = {}\n'); | ||
|
||
// packages/core/fs | ||
await cp(Paths['root/']('packages/core/fs/lib'), Paths['~/']('fs')); | ||
await cp( | ||
Paths['root/']('packages/core/fs/index.d.ts'), | ||
Paths['~/']('fs/index.d.ts'), | ||
); | ||
|
||
// packages/utils/domain-sharding | ||
await cp( | ||
Paths['root/']('packages/utils/domain-sharding/lib'), | ||
Paths['~/']('domain-sharding'), | ||
); | ||
|
||
// packages/utils/ts-utils | ||
await cp( | ||
Paths['root/']('packages/utils/ts-utils/lib'), | ||
Paths['~/']('ts-utils'), | ||
); | ||
|
||
// packages/core/plugin | ||
await cp(Paths['root/']('packages/core/plugin/lib'), Paths['~/']('plugin')); | ||
await cp( | ||
Paths['root/']('packages/core/plugin/src/PluginAPI.d.ts'), | ||
Paths['~/']('plugin/PluginAPI.d.ts'), | ||
); | ||
|
||
await writeFile( | ||
Paths['~/']('plugin/index.js'), | ||
'module.exports = require("./PluginAPI.js")', | ||
); | ||
await writeFile( | ||
Paths['~/']('plugin/index.d.ts'), | ||
'export * from "./PluginAPI"', | ||
); | ||
|
||
// packages/utils/node-resolver-core | ||
await cp( | ||
Paths['root/']('packages/utils/node-resolver-core/lib'), | ||
Paths['~/']('node-resolver-core'), | ||
); | ||
|
||
// packages/core/cache | ||
await cp(Paths['root/']('packages/core/cache/lib'), Paths['~/']('cache')); | ||
await writeFile(Paths['~/']('cache/index.d.ts'), 'export * from "./types"'); | ||
|
||
// packages/core/graph | ||
await cp(Paths['root/']('packages/core/graph/lib'), Paths['~/']('graph')); | ||
|
||
// packages/core/package-manager | ||
await cp( | ||
Paths['root/']('packages/core/package-manager/lib'), | ||
Paths['~/']('package-manager'), | ||
); | ||
await cp( | ||
Paths['root/']('packages/core/package-manager/index.d.ts'), | ||
Paths['~/']('package-manager/index.d.ts'), | ||
); | ||
|
||
// packages/core/core | ||
await cp(Paths['root/']('packages/core/core/lib'), Paths['~/']('core')); | ||
await cp( | ||
Paths['root/']('packages/core/core/index.d.ts'), | ||
Paths['~/']('core/index.d.ts'), | ||
); | ||
|
||
// packages/core/cli | ||
await cp(Paths['root/']('packages/core/cli/lib'), Paths['~/']('cli')); | ||
await writeFile( | ||
Paths['~/']('cli/index.js'), | ||
`#!/usr/bin/env node | ||
'use strict'; require('./cli');`, | ||
); | ||
} |
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,76 @@ | ||
import * as path from 'node:path'; | ||
import * as fs from 'node:fs'; | ||
import glob from 'glob'; | ||
import {Paths} from './paths.ts'; | ||
import {writeFile, readJson, rm, cp} from './fs.ts'; | ||
|
||
export async function buildPlugins() { | ||
// Plugins | ||
const skip = { | ||
'bundler-experimental': true, | ||
'repl-runtimes': true, | ||
'@atlaspack/reporter-dev-server': true, | ||
}; | ||
|
||
const override = { | ||
['runtimes/hmr']: Paths['~/']('runtimes/browser-hmr'), | ||
}; | ||
|
||
for (const folder of [ | ||
'bundlers', | ||
'compressors', | ||
'namers', | ||
'optimizers', | ||
'packagers', | ||
'reporters', | ||
'resolvers', | ||
'runtimes', | ||
'transformers', | ||
'validators', | ||
]) | ||
for (const target of fs.readdirSync(Paths['root/']('packages', folder))) { | ||
if (skip[target]) continue; | ||
const from = Paths['root/']('packages', folder, target); | ||
const to = override[`${folder}/${target}`] | ||
? override[`${folder}/${target}`] | ||
: Paths['~/'](folder, target); | ||
|
||
const {main, name} = await readJson<{main: string; name: string}>( | ||
path.join(from, 'package.json'), | ||
); | ||
if (skip[name]) continue; | ||
|
||
const relMain = main.replace('lib/', ''); | ||
await cp(path.join(from, 'lib'), to); | ||
|
||
if (relMain.endsWith('index.js')) continue; | ||
await writeFile( | ||
path.join(to, 'index.js'), | ||
`module.exports = require('./${relMain}');\n`, | ||
); | ||
} | ||
|
||
await cp( | ||
Paths['root/']('packages/reporters/dev-server/lib'), | ||
Paths['~/']('reporters/dev-server/lib'), | ||
); | ||
|
||
await cp( | ||
Paths['root/']('packages/reporters/dev-server/src/templates'), | ||
Paths['~/']('reporters/dev-server/src/templates'), | ||
); | ||
|
||
await writeFile( | ||
Paths['~/']('reporters/dev-server/index.js'), | ||
`module.exports = require('./lib/ServerReporter.js');\n`, | ||
); | ||
|
||
// Configs | ||
await cp(Paths['root/']('packages/configs'), Paths['~/']('configs')); | ||
|
||
await rm( | ||
...glob.sync(Paths['~/']('configs/**/package.json')), | ||
...glob.sync(Paths['~/']('configs/**/test')), | ||
...glob.sync(Paths['~/']('**/CHANGELOG.md')), | ||
); | ||
} |
Oops, something went wrong.