Skip to content

Commit ab585f6

Browse files
Merge branch 'canary' into fix/gsp-compile-query
2 parents 0372db9 + d73b836 commit ab585f6

File tree

10 files changed

+110
-72
lines changed

10 files changed

+110
-72
lines changed

.github/actions/next-stats-action/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"dependencies": {
55
"async-sema": "^3.1.0",
66
"execa": "2.0.3",
7-
"fs-extra": "^8.1.0",
87
"get-port": "^5.0.0",
98
"glob": "^7.1.4",
109
"gzip-size": "^5.1.1",

.github/actions/next-stats-action/src/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path')
2-
const fs = require('fs-extra')
2+
const fs = require('fs/promises')
3+
const { existsSync } = require('fs')
34
const exec = require('./util/exec')
45
const logger = require('./util/logger')
56
const runConfigs = require('./run')
@@ -21,7 +22,7 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
2122

2223
;(async () => {
2324
try {
24-
if (await fs.pathExists(path.join(__dirname, '../SKIP_NEXT_STATS.txt'))) {
25+
if (existsSync(path.join(__dirname, '../SKIP_NEXT_STATS.txt'))) {
2526
console.log(
2627
'SKIP_NEXT_STATS.txt file present, exiting stats generation..'
2728
)
@@ -100,7 +101,7 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
100101
for (const dir of repoDirs) {
101102
logger(`Running initial build for ${dir}`)
102103
if (!actionInfo.skipClone) {
103-
const usePnpm = await fs.pathExists(path.join(dir, 'pnpm-lock.yaml'))
104+
const usePnpm = existsSync(path.join(dir, 'pnpm-lock.yaml'))
104105

105106
if (!statsConfig.skipInitialInstall) {
106107
await exec.spawnPromise(
@@ -121,9 +122,10 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
121122
}
122123

123124
await fs
124-
.copy(
125+
.cp(
125126
path.join(__dirname, '../native'),
126-
path.join(dir, 'packages/next-swc/native')
127+
path.join(dir, 'packages/next-swc/native'),
128+
{ recursive: true, force: true }
127129
)
128130
.catch(console.error)
129131

.github/actions/next-stats-action/src/prepare/repo-setup.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
const path = require('path')
2-
const fse = require('fs-extra')
3-
const fs = require('fs')
4-
const fsp = require('fs/promises')
2+
const fs = require('fs/promises')
3+
const { existsSync } = require('fs')
54
const exec = require('../util/exec')
6-
const { remove } = require('fs-extra')
75
const logger = require('../util/logger')
86
const execa = require('execa')
97

108
module.exports = (actionInfo) => {
119
return {
1210
async cloneRepo(repoPath = '', dest = '', branch = '', depth = '20') {
13-
await remove(dest)
11+
await fs.rm(dest, { recursive: true, force: true })
1412
await exec(
1513
`git clone ${actionInfo.gitRoot}${repoPath} --single-branch --branch ${branch} --depth=${depth} ${dest}`
1614
)
@@ -72,7 +70,7 @@ module.exports = (actionInfo) => {
7270
let pkgs
7371

7472
try {
75-
pkgs = await fsp.readdir(path.join(repoDir, 'packages'))
73+
pkgs = await fs.readdir(path.join(repoDir, 'packages'))
7674
} catch (err) {
7775
if (err.code === 'ENOENT') {
7876
require('console').log('no packages to link')
@@ -87,8 +85,8 @@ module.exports = (actionInfo) => {
8785
const packedPkgPath = path.join(pkgPath, `${pkg}-packed.tgz`)
8886

8987
const pkgDataPath = path.join(pkgPath, 'package.json')
90-
if (fs.existsSync(pkgDataPath)) {
91-
const pkgData = JSON.parse(await fsp.readFile(pkgDataPath))
88+
if (existsSync(pkgDataPath)) {
89+
const pkgData = JSON.parse(await fs.readFile(pkgDataPath))
9290
const { name } = pkgData
9391

9492
pkgDatas.set(name, {
@@ -122,7 +120,7 @@ module.exports = (actionInfo) => {
122120
pkgData.files.push('native')
123121

124122
try {
125-
const swcBinariesDirContents = await fsp.readdir(
123+
const swcBinariesDirContents = await fs.readdir(
126124
path.join(pkgPath, 'native')
127125
)
128126
require('console').log(
@@ -155,7 +153,7 @@ module.exports = (actionInfo) => {
155153
}
156154
}
157155

158-
await fsp.writeFile(
156+
await fs.writeFile(
159157
pkgDataPath,
160158
JSON.stringify(pkgData, null, 2),
161159
'utf8'
@@ -186,9 +184,9 @@ module.exports = (actionInfo) => {
186184
'disabled-native-gitignore'
187185
)
188186

189-
await fsp.rename(nativeGitignorePath, renamedGitignorePath)
187+
await fs.rename(nativeGitignorePath, renamedGitignorePath)
190188
cleanup = async () => {
191-
await fsp.rename(renamedGitignorePath, nativeGitignorePath)
189+
await fs.rename(renamedGitignorePath, nativeGitignorePath)
192190
}
193191
}
194192

@@ -201,7 +199,7 @@ module.exports = (actionInfo) => {
201199
})
202200

203201
return Promise.all([
204-
fsp.rename(path.resolve(pkgPath, stdout.trim()), packedPkgPath),
202+
fs.rename(path.resolve(pkgPath, stdout.trim()), packedPkgPath),
205203
cleanup?.(),
206204
])
207205
}

.github/actions/next-stats-action/src/run/collect-diffs.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path')
2-
const fs = require('fs-extra')
2+
const fs = require('fs/promises')
3+
const { existsSync } = require('fs')
34
const exec = require('../util/exec')
45
const glob = require('../util/glob')
56
const logger = require('../util/logger')
@@ -12,15 +13,17 @@ module.exports = async function collectDiffs(
1213
if (initial) {
1314
logger('Setting up directory for diffing')
1415
// set-up diffing directory
15-
await fs.remove(diffingDir)
16-
await fs.mkdirp(diffingDir)
16+
await fs.rm(diffingDir, { recursive: true, force: true })
17+
await fs.mkdir(diffingDir, { recursive: true })
1718
await exec(`cd ${diffingDir} && git init`)
1819
} else {
1920
// remove any previous files in case they won't be overwritten
2021
const toRemove = await glob('!(.git)', { cwd: diffingDir, dot: true })
2122

2223
await Promise.all(
23-
toRemove.map((file) => fs.remove(path.join(diffingDir, file)))
24+
toRemove.map((file) =>
25+
fs.rm(path.join(diffingDir, file), { recursive: true, force: true })
26+
)
2427
)
2528
}
2629
const diffs = {}
@@ -40,7 +43,7 @@ module.exports = async function collectDiffs(
4043
const absPath = path.join(statsAppDir, file)
4144

4245
const diffDest = path.join(diffingDir, file)
43-
await fs.copy(absPath, diffDest)
46+
await fs.cp(absPath, diffDest, { recursive: true, force: true })
4447
}
4548

4649
if (curFiles.length > 0) {
@@ -75,7 +78,7 @@ module.exports = async function collectDiffs(
7578

7679
for (const line of renamedFiles) {
7780
const [, prev, cur] = line.split('\t')
78-
await fs.move(path.join(diffingDir, cur), path.join(diffingDir, prev))
81+
await fs.rename(path.join(diffingDir, cur), path.join(diffingDir, prev))
7982
diffs._renames.push({
8083
prev,
8184
cur,
@@ -91,7 +94,7 @@ module.exports = async function collectDiffs(
9194

9295
for (const file of changedFiles) {
9396
const fileKey = path.basename(file)
94-
const hasFile = await fs.exists(path.join(diffingDir, file))
97+
const hasFile = existsSync(path.join(diffingDir, file))
9598

9699
if (!hasFile) {
97100
diffs[fileKey] = 'deleted'

.github/actions/next-stats-action/src/run/collect-stats.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const path = require('path')
2-
const fs = require('fs-extra')
2+
const fs = require('fs/promises')
33
const getPort = require('get-port')
44
const fetch = require('node-fetch')
55
const glob = require('../util/glob')
@@ -84,7 +84,7 @@ module.exports = async function collectStats(
8484

8585
if (hasPagesToFetch) {
8686
const fetchedPagesDir = path.join(curDir, 'fetched-pages')
87-
await fs.mkdirp(fetchedPagesDir)
87+
await fs.mkdir(fetchedPagesDir, { recursive: true })
8888

8989
for (let url of runConfig.pagesToFetch) {
9090
url = url.replace('$PORT', port)

.github/actions/next-stats-action/src/run/get-dir-size.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const path = require('path')
2-
const fs = require('fs-extra')
2+
const fs = require('fs/promises')
33

44
// getDirSize recursively gets size of all files in a directory
55
async function getDirSize(dir, ctx = { size: 0 }) {

.github/actions/next-stats-action/src/run/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const path = require('path')
2-
const fs = require('fs-extra')
2+
const fs = require('fs/promises')
33
const glob = require('../util/glob')
44
const exec = require('../util/exec')
55
const logger = require('../util/logger')
@@ -36,8 +36,8 @@ async function runConfigs(
3636
const curStatsAppPath = path.join(diffRepoDir, relativeStatsAppDir)
3737

3838
// clean statsAppDir
39-
await fs.remove(statsAppDir)
40-
await fs.copy(curStatsAppPath, statsAppDir)
39+
await fs.rm(statsAppDir, { recursive: true, force: true })
40+
await fs.cp(curStatsAppPath, statsAppDir, { recursive: true })
4141

4242
logger(`Copying ${curStatsAppPath} ${statsAppDir}`)
4343

@@ -70,7 +70,7 @@ async function runConfigs(
7070
? result.replace(/(\.|-)[0-9a-f]{16}(\.|-)/g, '$1HASH$2')
7171
: rename.dest
7272
if (result === dest) continue
73-
await fs.move(
73+
await fs.rename(
7474
path.join(statsAppDir, result),
7575
path.join(statsAppDir, dest)
7676
)
@@ -172,7 +172,10 @@ async function runConfigs(
172172
}
173173

174174
async function linkPkgs(pkgDir = '', pkgPaths) {
175-
await fs.remove(path.join(pkgDir, 'node_modules'))
175+
await fs.rm(path.join(pkgDir, 'node_modules'), {
176+
recursive: true,
177+
force: true,
178+
})
176179

177180
const pkgJsonPath = path.join(pkgDir, 'package.json')
178181
const pkgData = require(pkgJsonPath)

.github/pnpm-lock.yaml

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/next-swc/crates/next-core/src/next_client/context.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,29 @@ pub async fn get_client_module_options_context(
212212
false,
213213
next_config,
214214
);
215-
let webpack_rules =
216-
*maybe_add_babel_loader(project_path, *next_config.webpack_rules().await?).await?;
217-
let webpack_rules = maybe_add_sass_loader(next_config.sass_config(), webpack_rules).await?;
215+
216+
// A separate webpack rules will be applied to codes matching
217+
// foreign_code_context_condition. This allows to import codes from
218+
// node_modules that requires webpack loaders, which next-dev implicitly
219+
// does by default.
220+
let foreign_webpack_rules = maybe_add_sass_loader(
221+
next_config.sass_config(),
222+
*next_config.webpack_rules().await?,
223+
)
224+
.await?;
225+
let foreign_webpack_loaders = foreign_webpack_rules.map(|rules| {
226+
WebpackLoadersOptions {
227+
rules,
228+
loader_runner_package: Some(get_external_next_compiled_package_mapping(Vc::cell(
229+
"loader-runner".to_owned(),
230+
))),
231+
}
232+
.cell()
233+
});
234+
235+
// Now creates a webpack rules that applies to all codes.
236+
let webpack_rules = *foreign_webpack_rules.clone();
237+
let webpack_rules = *maybe_add_babel_loader(project_path, webpack_rules).await?;
218238
let enable_webpack_loaders = webpack_rules.map(|rules| {
219239
WebpackLoadersOptions {
220240
rules,
@@ -252,9 +272,14 @@ pub async fn get_client_module_options_context(
252272
preset_env_versions: Some(env),
253273
execution_context: Some(execution_context),
254274
custom_ecma_transform_plugins,
275+
..Default::default()
276+
};
277+
278+
let foreign_codes_options_context = ModuleOptionsContext {
279+
enable_webpack_loaders: foreign_webpack_loaders,
255280
// NOTE(WEB-1016) PostCSS transforms should also apply to foreign code.
256281
enable_postcss_transform: postcss_transform_options.clone(),
257-
..Default::default()
282+
..module_options_context.clone()
258283
};
259284

260285
let module_options_context = ModuleOptionsContext {
@@ -270,7 +295,7 @@ pub async fn get_client_module_options_context(
270295
rules: vec![
271296
(
272297
foreign_code_context_condition(next_config, project_path).await?,
273-
module_options_context.clone().cell(),
298+
foreign_codes_options_context.cell(),
274299
),
275300
// If the module is an internal asset (i.e overlay, fallback) coming from the embedded
276301
// FS, don't apply user defined transforms.

0 commit comments

Comments
 (0)