Skip to content

Commit c9309f2

Browse files
authored
feat(relay): Port patches from next.js repo (#164)
1 parent 5ed4fcf commit c9309f2

File tree

18 files changed

+43
-21
lines changed

18 files changed

+43
-21
lines changed

Cargo.lock

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

packages/emotion/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@swc/plugin-emotion",
3-
"version": "2.5.49",
3+
"version": "2.5.50",
44
"description": "SWC plugin for emotion css-in-js library",
55
"main": "swc_plugin_emotion.wasm",
66
"scripts": {

packages/emotion/transform/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
license = "Apache-2.0"
66
name = "swc_emotion"
77
repository = "https://github.com/swc-project/plugins.git"
8-
version = "0.29.12"
8+
version = "0.29.13"
99

1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

packages/jest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@swc/plugin-jest",
3-
"version": "1.5.49",
3+
"version": "1.5.50",
44
"description": "SWC plugin for jest",
55
"main": "swc_plugin_jest.wasm",
66
"scripts": {

packages/loadable-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@swc/plugin-loadable-components",
3-
"version": "0.3.49",
3+
"version": "0.3.50",
44
"description": "SWC plugin for `@loadable/components`",
55
"main": "swc_plugin_loadable_components.wasm",
66
"scripts": {

packages/noop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@swc/plugin-noop",
3-
"version": "1.5.47",
3+
"version": "1.5.48",
44
"description": "Noop SWC plugin, for debugging",
55
"main": "swc_plugin_noop.wasm",
66
"scripts": {

packages/relay/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@swc/plugin-relay",
3-
"version": "1.5.49",
3+
"version": "1.5.50",
44
"description": "SWC plugin for relay",
55
"main": "swc_plugin_relay.wasm",
66
"types": "./types.d.ts",

packages/relay/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn relay_plugin_transform(program: Program, metadata: TransformPluginProgramMeta
5050
eager_es_modules,
5151
};
5252

53-
let mut relay = relay(&config, filename, root_dir);
53+
let mut relay = relay(&config, filename, root_dir, None);
5454

5555
program.fold_with(&mut relay)
5656
}

packages/relay/transform/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
license = "Apache-2.0"
66
name = "swc_relay"
77
repository = "https://github.com/swc-project/plugins.git"
8-
version = "0.1.0"
8+
version = "0.1.1"
99

1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

packages/relay/transform/src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use swc_core::{
2121
#[serde(rename_all = "lowercase")]
2222
pub enum RelayLanguageConfig {
2323
TypeScript,
24+
JavaScript,
2425
Flow,
2526
}
2627

@@ -69,6 +70,7 @@ impl RelayImport {
6970

7071
struct Relay<'a> {
7172
root_dir: PathBuf,
73+
pages_dir: Option<PathBuf>,
7274
file_name: FileName,
7375
config: &'a Config,
7476
imports: Vec<RelayImport>,
@@ -147,6 +149,7 @@ fn unique_ident_name_from_operation_name(operation_name: &str) -> String {
147149
#[derive(Debug)]
148150
enum BuildRequirePathError {
149151
FileNameNotReal,
152+
ArtifactDirectoryExpected { file_name: String },
150153
}
151154

152155
impl<'a> Relay<'a> {
@@ -160,10 +163,21 @@ impl<'a> Relay<'a> {
160163
RelayLanguageConfig::TypeScript => {
161164
format!("{}.graphql.ts", definition_name)
162165
}
166+
RelayLanguageConfig::JavaScript => {
167+
format!("{}.graphql.js", definition_name)
168+
}
163169
};
164170

165171
if let Some(artifact_directory) = &self.config.artifact_directory {
166172
Ok(self.root_dir.join(artifact_directory).join(filename))
173+
} else if self
174+
.pages_dir
175+
.as_ref()
176+
.map_or(false, |pages_dir| real_file_name.starts_with(pages_dir))
177+
{
178+
Err(BuildRequirePathError::ArtifactDirectoryExpected {
179+
file_name: real_file_name.display().to_string(),
180+
})
167181
} else {
168182
Ok(real_file_name
169183
.parent()
@@ -243,11 +257,17 @@ impl<'a> Relay<'a> {
243257
}
244258
}
245259

246-
pub fn relay(config: &Config, file_name: FileName, root_dir: PathBuf) -> impl Fold + '_ {
260+
pub fn relay(
261+
config: &Config,
262+
file_name: FileName,
263+
root_dir: PathBuf,
264+
pages_dir: Option<PathBuf>,
265+
) -> impl Fold + '_ {
247266
Relay {
248267
root_dir,
249268
file_name,
250269
config,
270+
pages_dir,
251271
imports: vec![],
252272
}
253273
}

packages/relay/transform/tests/fixture.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn fixture(input: PathBuf) {
1919
},
2020
FileName::Real("file.js".parse().unwrap()),
2121
Default::default(),
22+
None,
2223
)
2324
},
2425
&input,
@@ -42,6 +43,7 @@ fn fixture_es_modules(input: PathBuf) {
4243
},
4344
FileName::Real("file.js".parse().unwrap()),
4445
Default::default(),
46+
None,
4547
)
4648
},
4749
&input,

packages/relay/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ declare module "@swc/plugin-relay" {
22
export interface Config {
33
rootDir: string;
44
artifactDirectory?: string;
5-
language: "typescript" | "flow";
5+
language: "typescript" | "javascrip" | "flow";
66
eagerEsModules?: boolean;
77
}
88
}

packages/styled-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@swc/plugin-styled-components",
3-
"version": "1.5.49",
3+
"version": "1.5.50",
44
"description": "SWC plugin for styled-components",
55
"main": "swc_plugin_styled_components.wasm",
66
"scripts": {

packages/styled-components/transform/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
66
license = "Apache-2.0"
77
name = "styled_components"
88
repository = "https://github.com/swc-project/plugins.git"
9-
version = "0.53.12"
9+
version = "0.53.13"
1010

1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

packages/styled-jsx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@swc/plugin-styled-jsx",
3-
"version": "1.5.49",
3+
"version": "1.5.50",
44
"description": "SWC plugin for styled-jsx",
55
"main": "swc_plugin_styled_jsx.wasm",
66
"scripts": {

packages/styled-jsx/transform/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description = "AST transforms visitor for styled-jsx"
44
edition = "2021"
55
license = "Apache-2.0"
66
name = "styled_jsx"
7-
version = "0.30.12"
7+
version = "0.30.13"
88

99
[features]
1010
custom_transform = ["swc_core/common_concurrent"]

packages/transform-imports/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@swc/plugin-transform-imports",
3-
"version": "1.5.49",
3+
"version": "1.5.50",
44
"description": "SWC plugin for https://www.npmjs.com/package/babel-plugin-transform-imports",
55
"main": "swc_plugin_transform_imports.wasm",
66
"scripts": {

packages/transform-imports/transform/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
license = "Apache-2.0"
66
name = "modularize_imports"
77
repository = "https://github.com/swc-project/plugins.git"
8-
version = "0.26.12"
8+
version = "0.26.13"
99

1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

0 commit comments

Comments
 (0)