Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove site and projectRoot options #693

Merged
merged 4 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/friendly-clouds-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': minor
---

Remove `site` and `projectRoot` options in favour of the `injectGlobals` option
13 changes: 2 additions & 11 deletions cmd/astro-wasm/astro-wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,7 @@ func makeTransformOptions(options js.Value) transform.TransformOptions {
sourcemap = "both"
}

site := jsString(options.Get("site"))
if site == "" {
site = ""
}

projectRoot := jsString(options.Get("projectRoot"))
if projectRoot == "" {
projectRoot = "."
}
injectGlobals := jsString(options.Get("injectGlobals"))
bluwy marked this conversation as resolved.
Show resolved Hide resolved

compact := false
if jsBool(options.Get("compact")) {
Expand Down Expand Up @@ -125,8 +117,7 @@ func makeTransformOptions(options js.Value) transform.TransformOptions {
ModuleId: moduleId,
InternalURL: internalURL,
SourceMap: sourcemap,
Site: site,
ProjectRoot: projectRoot,
InjectGlobals: injectGlobals,
Compact: compact,
ResolvePath: resolvePathFn,
PreprocessStyle: preprocessStyle,
Expand Down
9 changes: 1 addition & 8 deletions internal/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,7 @@ func (p *printer) addNilSourceMapping() {
}

func (p *printer) printTopLevelAstro(opts transform.TransformOptions) {
patharg := opts.Pathname
if patharg == "" {
patharg = "import.meta.url"
} else {
patharg = fmt.Sprintf("\"%s\"", patharg)
}

p.println(fmt.Sprintf("const $$Astro = %s(%s, '%s', '%s');\nconst Astro = $$Astro;", CREATE_ASTRO, patharg, p.opts.Site, p.opts.ProjectRoot))
p.println(fmt.Sprintf("const $$Astro = %s(%s);\nconst Astro = $$Astro;", CREATE_ASTRO, opts.InjectGlobals))
}

func remove(slice []*astro.Node, node *astro.Node) []*astro.Node {
Expand Down
2 changes: 0 additions & 2 deletions internal/printer/printer_css_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ func TestPrinterCSS(t *testing.T) {
transform.Transform(doc, transform.TransformOptions{Scope: hash}, handler.NewHandler(code, "/test.astro")) // note: we want to test Transform in context here, but more advanced cases could be tested separately
result := PrintCSS(code, doc, transform.TransformOptions{
Scope: "astro-XXXX",
Site: "https://astro.build",
InternalURL: "http://localhost:3000/",
ProjectRoot: ".",
})
output := ""
for _, bytes := range result.Output {
Expand Down
11 changes: 5 additions & 6 deletions internal/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var RETURN = fmt.Sprintf("return %s%s", TEMPLATE_TAG, BACKTICK)
var SUFFIX = fmt.Sprintf("%s;", BACKTICK) + `
});
export default $$Component;`
var CREATE_ASTRO_CALL = "const $$Astro = $$createAstro(import.meta.url, 'https://astro.build', '.');\nconst Astro = $$Astro;"
var CREATE_ASTRO_CALL = "const $$Astro = $$createAstro('https://astro.build');\nconst Astro = $$Astro;"
var RENDER_HEAD_RESULT = "${$$renderHead($$result)}"

// SPECIAL TEST FIXTURES
Expand Down Expand Up @@ -2337,11 +2337,10 @@ const items = ["Dog", "Cat", "Platipus"];
transform.ExtractStyles(doc)
transform.Transform(doc, transform.TransformOptions{Scope: hash}, h) // note: we want to test Transform in context here, but more advanced cases could be tested separately
result := PrintToJS(code, doc, 0, transform.TransformOptions{
Scope: "XXXX",
Site: "https://astro.build",
InternalURL: "http://localhost:3000/",
ModuleId: tt.moduleId,
ProjectRoot: ".",
Scope: "XXXX",
InternalURL: "http://localhost:3000/",
ModuleId: tt.moduleId,
InjectGlobals: "'https://astro.build'",
}, h)
output := string(result.Output)

Expand Down
3 changes: 1 addition & 2 deletions internal/transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ type TransformOptions struct {
ModuleId string
InternalURL string
SourceMap string
Site string
ProjectRoot string
InjectGlobals string
Compact bool
ResolvePath func(string) string
PreprocessStyle interface{}
Expand Down
1 change: 0 additions & 1 deletion packages/compiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ The Astro compiler can convert `.astro` syntax to a TypeScript Module whose defa
import { transform } from '@astrojs/compiler';

const result = await transform(source, {
site: 'https://mysite.dev',
sourcefile: '/Users/astro/Code/project/src/pages/index.astro',
sourcemap: 'both',
internalURL: 'astro/runtime/server/index.js',
Expand Down
3 changes: 1 addition & 2 deletions packages/compiler/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@ export interface DiagnosticLocation {

export interface TransformOptions {
internalURL?: string;
site?: string;
sourcefile?: string;
pathname?: string;
moduleId?: string;
sourcemap?: boolean | 'inline' | 'external' | 'both';
injectGlobals?: string;
compact?: boolean;
/**
* @deprecated "as" has been removed and no longer has any effect!
*/
as?: 'document' | 'fragment';
projectRoot?: string;
resolvePath?: (specifier: string) => Promise<string>;
preprocessStyle?: (content: string, attrs: Record<string, string>) => null | Promise<PreprocessorResult | PreprocessorError>;
}
Expand Down