attio 0.0.1-experimental.20240916.2 → 0.0.1-experimental.20240917

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.
@@ -3,14 +3,14 @@ import { glob } from "glob";
3
3
  import path from "path";
4
4
  const ROUTE_FILE_EXTENSIONS = ["tsx", "jsx", "ts", "js"];
5
5
  const ASSET_FILE_EXTENSIONS = ["png"];
6
- export async function generateClientEntry({ filePath, appDir, assetsDir, routes, log, }) {
6
+ export async function generateClientEntry({ appDir, appDirAbsolute, assetsDirAbsolute, routes, log, }) {
7
7
  log?.(`💥 Found entry point at ${path.resolve(appDir)}`);
8
8
  const paths = routes.flatMap((route) => ROUTE_FILE_EXTENSIONS.map((fileExtension) => route + "." + fileExtension));
9
9
  const concreteRoutes = (await Promise.all(paths.map(async (path) => {
10
10
  try {
11
11
  const concretePaths = await glob(path, {
12
12
  nodir: true,
13
- cwd: appDir,
13
+ cwd: appDirAbsolute,
14
14
  });
15
15
  for (const concretePath of concretePaths) {
16
16
  log?.(`🔎 Found route "${concretePath}"`);
@@ -26,7 +26,7 @@ export async function generateClientEntry({ filePath, appDir, assetsDir, routes,
26
26
  }))).flat();
27
27
  let assetFiles;
28
28
  try {
29
- assetFiles = await fs.readdir(assetsDir, { recursive: true });
29
+ assetFiles = await fs.readdir(assetsDirAbsolute, { recursive: true });
30
30
  }
31
31
  catch {
32
32
  assetFiles = [];
@@ -34,19 +34,19 @@ export async function generateClientEntry({ filePath, appDir, assetsDir, routes,
34
34
  const assets = assetFiles
35
35
  .filter((relativeAssetPath) => ASSET_FILE_EXTENSIONS.some((extension) => relativeAssetPath.endsWith(extension)))
36
36
  .map((relativeAssetPath) => ({
37
- path: path.join(assetsDir, relativeAssetPath),
37
+ path: path.join(assetsDirAbsolute, relativeAssetPath),
38
38
  name: relativeAssetPath,
39
39
  }));
40
40
  return `
41
41
  ${concreteRoutes
42
- .map((routeAndPath, index) => `import C${index} from ${JSON.stringify(path.relative(filePath, path.join(appDir, routeAndPath.path)))}`)
42
+ .map((routeAndPath, index) => `import C${index} from ${JSON.stringify(path.join(appDirAbsolute, routeAndPath.path))}`)
43
43
  .join("\n")}
44
44
 
45
45
  const assets = []
46
46
 
47
47
  ${assets
48
48
  .map((asset, index) => `
49
- import A${index} from ${JSON.stringify(path.relative(filePath, asset.path))};
49
+ import A${index} from ${JSON.stringify(asset.path)};
50
50
 
51
51
  assets.push({name: ${JSON.stringify(asset.name)}, data: A${index}})
52
52
  `)
@@ -1,15 +1,15 @@
1
1
  import { glob } from "glob";
2
2
  import path from "path";
3
3
  import { getModuleHash } from "../get-module-hash.js";
4
- export async function generateServerEntry({ appDir, webhooksDir, filePath, log, }) {
4
+ export async function generateServerEntry({ appDirAbsolute, webhooksDirAbsolute, log, }) {
5
5
  const [serverFunctionConcretePaths, webhookConcretePaths] = await Promise.all([
6
6
  Promise.all([
7
- glob("**/*.server.ts", { nodir: true, cwd: appDir }),
8
- glob("**/*.server.js", { nodir: true, cwd: appDir }),
7
+ glob("**/*.server.ts", { nodir: true, cwd: appDirAbsolute }),
8
+ glob("**/*.server.js", { nodir: true, cwd: appDirAbsolute }),
9
9
  ]).then((paths) => paths.flat()),
10
10
  Promise.all([
11
- glob("**/*.webhook.ts", { nodir: true, cwd: webhooksDir }),
12
- glob("**/*.webhook.js", { nodir: true, cwd: webhooksDir }),
11
+ glob("**/*.webhook.ts", { nodir: true, cwd: webhooksDirAbsolute }),
12
+ glob("**/*.webhook.js", { nodir: true, cwd: webhooksDirAbsolute }),
13
13
  ]).then((paths) => paths.flat()),
14
14
  ]);
15
15
  const serverFunctionModules = serverFunctionConcretePaths.map((path) => ({
@@ -30,11 +30,11 @@ export async function generateServerEntry({ appDir, webhooksDir, filePath, log,
30
30
 
31
31
 
32
32
  ${serverFunctionModules
33
- .map((module) => `modules.set("${module.hash}", () => import(${JSON.stringify(path.relative(filePath, path.join(appDir, module.path)))}))`)
33
+ .map((module) => `modules.set("${module.hash}", () => import(${JSON.stringify(path.join(appDirAbsolute, module.path))}))`)
34
34
  .join("\n")}
35
35
 
36
36
  ${webhookModules
37
- .map((module) => `webhookModules.set("${module.id}", () => import(${JSON.stringify(path.relative(filePath, path.join(webhooksDir, module.path)))}))`)
37
+ .map((module) => `webhookModules.set("${module.id}", () => import(${JSON.stringify(path.join(webhooksDirAbsolute, module.path))}))`)
38
38
  .join("\n")}
39
39
 
40
40
  var stdin_default;
@@ -32,9 +32,9 @@ export const jsMachine = setup({
32
32
  let lastJS;
33
33
  const updateTempFile = async () => {
34
34
  const js = await generateClientEntry({
35
- filePath: tempFile.path,
36
35
  appDir,
37
- assetsDir,
36
+ appDirAbsolute: path.resolve(appDir),
37
+ assetsDirAbsolute: path.resolve(assetsDir),
38
38
  routes: ROUTES,
39
39
  log,
40
40
  });
@@ -44,7 +44,6 @@ export const jsMachine = setup({
44
44
  lastJS = js;
45
45
  await fs.writeFile(tempFile.path, js);
46
46
  };
47
- await updateTempFile();
48
47
  const esbuildContext = await esbuild.context({
49
48
  ...createClientBuildConfig({
50
49
  entryPoint: tempFile.path,
@@ -71,9 +70,8 @@ export const jsMachine = setup({
71
70
  let lastJS;
72
71
  const updateTempFile = async () => {
73
72
  const js = await generateServerEntry({
74
- filePath: tempFile.path,
75
- appDir,
76
- webhooksDir,
73
+ appDirAbsolute: path.resolve(appDir),
74
+ webhooksDirAbsolute: path.resolve(webhooksDir),
77
75
  log,
78
76
  });
79
77
  if (js === lastJS) {
@@ -82,7 +80,6 @@ export const jsMachine = setup({
82
80
  lastJS = js;
83
81
  await fs.writeFile(tempFile.path, js);
84
82
  };
85
- await updateTempFile();
86
83
  const esbuildContext = await esbuild.context({
87
84
  ...createServerBuildConfig(tempFile.path),
88
85
  write,
@@ -2,6 +2,7 @@ const {FlatCompat} = require("@eslint/eslintrc")
2
2
  const js = require("@eslint/js")
3
3
  const reactPlugin = require("eslint-plugin-react")
4
4
  const reactHooksPlugin = require("eslint-plugin-react-hooks")
5
+ const attio = require("attio/lint")
5
6
 
6
7
  const compat = new FlatCompat({
7
8
  baseDirectory: __dirname,
@@ -25,11 +26,13 @@ module.exports = [
25
26
  plugins: {
26
27
  "react": reactPlugin,
27
28
  "react-hooks": reactHooksPlugin,
29
+ attio,
28
30
  },
29
31
  rules: {
30
32
  "react/jsx-key": "error",
31
33
  "react-hooks/rules-of-hooks": "error",
32
34
  "react-hooks/exhaustive-deps": "error",
35
+ "attio/attio-client-import": "error",
33
36
  },
34
37
  settings: {
35
38
  react: {
@@ -4,6 +4,7 @@ const reactPlugin = require("eslint-plugin-react")
4
4
  const reactHooksPlugin = require("eslint-plugin-react-hooks")
5
5
  const typescriptEslintPlugin = require("@typescript-eslint/eslint-plugin")
6
6
  const typescriptParser = require("@typescript-eslint/parser")
7
+ const attio = require("attio/lint")
7
8
 
8
9
  const compat = new FlatCompat({
9
10
  baseDirectory: __dirname,
@@ -31,12 +32,14 @@ module.exports = [
31
32
  "react": reactPlugin,
32
33
  "react-hooks": reactHooksPlugin,
33
34
  "@typescript-eslint": typescriptEslintPlugin,
35
+ attio,
34
36
  },
35
37
  rules: {
36
38
  "react/jsx-key": "error",
37
39
  "react-hooks/rules-of-hooks": "error",
38
40
  "react-hooks/exhaustive-deps": "error",
39
41
  "@typescript-eslint/no-unused-vars": "error",
42
+ "attio/attio-client-import": "error",
40
43
  },
41
44
  settings: {
42
45
  react: {
package/lint.cjs ADDED
@@ -0,0 +1,37 @@
1
+ module.exports = {
2
+ rules: {
3
+ "attio-client-import": {
4
+ meta: {
5
+ type: "problem",
6
+ docs: {
7
+ description: 'Disallow imports from "attio/client" in server files',
8
+ category: "Possible Errors",
9
+ recommended: true,
10
+ },
11
+ fixable: null,
12
+ },
13
+ create(context) {
14
+ return {
15
+ ImportDeclaration(node) {
16
+ if (node.source.value === "attio/client") {
17
+ const filename = context.getFilename()
18
+ if (filename.endsWith(".server.ts")) {
19
+ context.report({
20
+ node,
21
+ message:
22
+ 'Imports from "attio/client" are not allowed in .server.ts files',
23
+ })
24
+ } else if (filename.endsWith(".server.js")) {
25
+ context.report({
26
+ node,
27
+ message:
28
+ 'Imports from "attio/client" are not allowed in .server.js files',
29
+ })
30
+ }
31
+ }
32
+ },
33
+ }
34
+ },
35
+ },
36
+ },
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attio",
3
- "version": "0.0.1-experimental.20240916.2",
3
+ "version": "0.0.1-experimental.20240917",
4
4
  "bin": "lib/attio.js",
5
5
  "type": "module",
6
6
  "files": [
@@ -8,7 +8,8 @@
8
8
  "attio.js",
9
9
  "client.d.ts",
10
10
  "server.d.ts",
11
- "global.d.ts"
11
+ "global.d.ts",
12
+ "lint.cjs"
12
13
  ],
13
14
  "exports": {
14
15
  "./client": {
@@ -19,6 +20,9 @@
19
20
  },
20
21
  "./server": {
21
22
  "types": "./server.d.ts"
23
+ },
24
+ "./lint": {
25
+ "default": "./lint.cjs"
22
26
  }
23
27
  },
24
28
  "dependencies": {
@@ -45,6 +49,7 @@
45
49
  "murmurhash-js": "^1.0.0",
46
50
  "pastel": "^3.0.0",
47
51
  "react": "18.3.1",
52
+ "tmp-promise": "^3.0.3",
48
53
  "typescript": "5.4.5",
49
54
  "uuid": "^9.0.1",
50
55
  "xstate": "5.15.0",