@astrojs/ts-plugin 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ @astrojs/ts-plugin:build: cache hit, replaying output 74e970e8e478efe1
2
+ @astrojs/ts-plugin:build: $ astro-scripts build "src/**/*.ts"
package/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # @astrojs/ts-plugin
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6b6b47a: Remove internal astro.d.ts files, instead prefer the one provided by Astro itself
8
+
3
9
  ## 0.1.1
10
+
4
11
  ### Patch Changes
5
12
 
6
13
  - f1f3091: Fix commenting, namespaced elements, and Fragment typings
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @astrojs/ts-plugin
2
+
3
+ Work in progress TypeScript plugin adding support for `.astro` imports with proper typing
package/dist/astro2tsx.js CHANGED
@@ -24,9 +24,7 @@ __markAsModule(exports);
24
24
  __export(exports, {
25
25
  astro2tsx: () => astro2tsx
26
26
  });
27
- var import_fs = __toModule(require("fs"));
28
27
  var import_ts_morph = __toModule(require("ts-morph"));
29
- const ASTRO_DEFINITION = (0, import_fs.readFileSync)(require.resolve("../astro.d.ts"));
30
28
  function astro2tsx(code, options) {
31
29
  const compiled = transformContent(code);
32
30
  const result = {
@@ -37,7 +35,7 @@ function astro2tsx(code, options) {
37
35
  };
38
36
  return result;
39
37
  }
40
- function addProps(content, dtsContent) {
38
+ function addProps(content) {
41
39
  let defaultExportType = "Record<string, any>";
42
40
  const project = new import_ts_morph.Project({});
43
41
  const sourceFile = project.createSourceFile("testing.ts", content);
@@ -45,15 +43,15 @@ function addProps(content, dtsContent) {
45
43
  if (declarations.has("Props")) {
46
44
  defaultExportType = "Props";
47
45
  }
48
- return dtsContent + `
46
+ return `
49
47
  export default function (props: ${defaultExportType}): string;`;
50
48
  }
51
49
  function transformContent(content) {
52
50
  const ts = content.replace(/---/g, "///");
53
- return ts + addProps(ts, ASTRO_DEFINITION.toString("utf-8"));
51
+ return ts + addProps(ts);
54
52
  }
55
53
  // Annotate the CommonJS export names for ESM import in node:
56
54
  0 && (module.exports = {
57
55
  astro2tsx
58
56
  });
59
- //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2FzdHJvMnRzeC50cyJdLAogICJtYXBwaW5ncyI6ICI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUNBLGdCQUE2QjtBQUM3QixzQkFBd0I7QUFHeEIsTUFBTSxtQkFBbUIsNEJBQTZCO0FBaUIvQyxtQkFBbUIsTUFBYyxTQUE0QztBQUNsRixRQUFNLFdBQVksaUJBQWlCO0FBRW5DLFFBQU0sU0FBMEI7QUFBQSxJQUM5QixNQUFNO0FBQUEsSUFDTixLQUFLO0FBQUEsTUFDSCxVQUFVO0FBQUE7QUFBQTtBQUlkLFNBQU87QUFBQTtBQUlULGtCQUFrQixTQUFpQixZQUE0QjtBQUM3RCxNQUFJLG9CQUFvQjtBQUd4QixRQUFNLFVBQVUsSUFBSSx3QkFBUTtBQUM1QixRQUFNLGFBQWEsUUFBUSxpQkFBaUIsY0FBYztBQUMxRCxRQUFNLGVBQWUsV0FBVztBQUNoQyxNQUFHLGFBQWEsSUFBSSxVQUFVO0FBQzVCLHdCQUFvQjtBQUFBO0FBRXRCLFNBQU8sYUFBYTtBQUFBLGtDQUEwQztBQUFBO0FBR2hFLDBCQUEwQixTQUFpQjtBQUN6QyxRQUFNLEtBQUssUUFBUSxRQUFRLFFBQVE7QUFDbkMsU0FDRSxLQUVBLFNBQVMsSUFBSSxpQkFBaUIsU0FBUztBQUFBOyIsCiAgIm5hbWVzIjogW10KfQo=
57
+ //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2FzdHJvMnRzeC50cyJdLAogICJtYXBwaW5ncyI6ICI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUNBLHNCQUF3QjtBQWlCakIsbUJBQW1CLE1BQWMsU0FBNEM7QUFDbEYsUUFBTSxXQUFXLGlCQUFpQjtBQUVsQyxRQUFNLFNBQTBCO0FBQUEsSUFDOUIsTUFBTTtBQUFBLElBQ04sS0FBSztBQUFBLE1BQ0gsVUFBVTtBQUFBO0FBQUE7QUFJZCxTQUFPO0FBQUE7QUFJVCxrQkFBa0IsU0FBeUI7QUFDekMsTUFBSSxvQkFBb0I7QUFHeEIsUUFBTSxVQUFVLElBQUksd0JBQVE7QUFDNUIsUUFBTSxhQUFhLFFBQVEsaUJBQWlCLGNBQWM7QUFDMUQsUUFBTSxlQUFlLFdBQVc7QUFDaEMsTUFBRyxhQUFhLElBQUksVUFBVTtBQUM1Qix3QkFBb0I7QUFBQTtBQUV0QixTQUFPO0FBQUEsa0NBQTBDO0FBQUE7QUFHbkQsMEJBQTBCLFNBQWlCO0FBQ3pDLFFBQU0sS0FBSyxRQUFRLFFBQVEsUUFBUTtBQUNuQyxTQUNFLEtBRUEsU0FBUztBQUFBOyIsCiAgIm5hbWVzIjogW10KfQo=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/ts-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "A TypeScript Plugin providing Astro intellisense",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
@@ -14,7 +14,7 @@
14
14
  "build": "astro-scripts build \"src/**/*.ts\"",
15
15
  "dev": "astro-scripts dev \"src/**/*.ts\""
16
16
  },
17
- "author": "Skypack",
17
+ "author": "withastro",
18
18
  "license": "MIT",
19
19
  "devDependencies": {
20
20
  "@tsconfig/node12": "^1.0.0",
package/src/astro2tsx.ts CHANGED
@@ -1,10 +1,6 @@
1
1
  import type { FileMapping } from './source-mapper';
2
- import { readFileSync } from 'fs';
3
2
  import { Project } from 'ts-morph';
4
3
 
5
-
6
- const ASTRO_DEFINITION = readFileSync(require.resolve('../astro.d.ts'));
7
-
8
4
  // Note that this is a bit of a hack until the new compiler with proper
9
5
  // source map support.
10
6
 
@@ -21,7 +17,7 @@ interface Astro2TSXResult {
21
17
  }
22
18
 
23
19
  export function astro2tsx(code: string, options: Astro2TSXOptions): Astro2TSXResult {
24
- const compiled = transformContent(code);
20
+ const compiled = transformContent(code);
25
21
 
26
22
  const result: Astro2TSXResult = {
27
23
  code: compiled,
@@ -29,12 +25,12 @@ export function astro2tsx(code: string, options: Astro2TSXOptions): Astro2TSXRes
29
25
  mappings: []
30
26
  }
31
27
  };
32
-
28
+
33
29
  return result;
34
30
  }
35
31
 
36
32
  // This is hacky but it works for now
37
- function addProps(content: string, dtsContent: string): string {
33
+ function addProps(content: string): string {
38
34
  let defaultExportType = 'Record<string, any>';
39
35
 
40
36
  // See if this has an interface already
@@ -44,7 +40,7 @@ function addProps(content: string, dtsContent: string): string {
44
40
  if(declarations.has('Props')) {
45
41
  defaultExportType = 'Props';
46
42
  }
47
- return dtsContent + '\n' + `export default function (props: ${defaultExportType}): string;`
43
+ return '\n' + `export default function (props: ${defaultExportType}): string;`
48
44
  }
49
45
 
50
46
  function transformContent(content: string) {
@@ -52,6 +48,6 @@ function transformContent(content: string) {
52
48
  return (
53
49
  ts +
54
50
  // Add TypeScript definitions
55
- addProps(ts, ASTRO_DEFINITION.toString('utf-8'))
51
+ addProps(ts)
56
52
  );
57
- }
53
+ }
package/astro.d.ts DELETED
@@ -1,29 +0,0 @@
1
- type AstroRenderedHTML = string;
2
-
3
- type FetchContentResult<ContentFrontmatter extends Record<string, any> = Record<string, any>> = {
4
- astro: {
5
- headers: string[];
6
- source: string;
7
- html: AstroRenderedHTML;
8
- };
9
- url: URL;
10
- } & ContentFrontmatter;
11
-
12
- interface AstroPageRequest {
13
- url: URL;
14
- canonicalURL: URL;
15
- }
16
-
17
- interface Astro {
18
- isPage: boolean;
19
- fetchContent<ContentFrontmatter>(globStr: string): FetchContentResult<ContentFrontmatter>[];
20
- props: Record<string, number | string | any>;
21
- request: AstroPageRequest;
22
- site: URL;
23
- }
24
-
25
- declare var Astro: Astro;
26
- declare var Fragment: string;
27
-
28
- void Astro;
29
- void Fragment;