Browse Source

typescriptize

Yuki Takei 3 years ago
parent
commit
5b65662347

+ 4 - 2
packages/hackmd/package.json

@@ -3,8 +3,10 @@
   "version": "6.0.8-RC.0",
   "version": "6.0.8-RC.0",
   "description": "GROWI js and css files to use hackmd",
   "description": "GROWI js and css files to use hackmd",
   "license": "MIT",
   "license": "MIT",
-  "main": "dist/index.js",
-  "types": "types/hackmd-styles.d.ts",
+  "type": "module",
+  "main": "dist/index.cjs",
+  "module": "dist/index.js",
+  "types": "types/index.d.ts",
   "scripts": {
   "scripts": {
     "build": "vite build",
     "build": "vite build",
     "clean": "npx -y shx rm -rf dist types",
     "clean": "npx -y shx rm -rf dist types",

+ 0 - 0
packages/hackmd/src/hackmd-styles.js → packages/hackmd/src/hackmd-styles.ts


+ 6 - 5
packages/hackmd/public/index.js → packages/hackmd/src/index.ts

@@ -1,15 +1,16 @@
-const fs = require('fs');
-const path = require('path');
+import fs from 'node:fs';
+import path from 'node:path';
 
 
 const isProduction = process.env.NODE_ENV === 'production';
 const isProduction = process.env.NODE_ENV === 'production';
 const dirPath = isProduction ? '.' : '../dist';
 const dirPath = isProduction ? '.' : '../dist';
-const stylesJSFile = fs.readFileSync(path.resolve(__dirname, `${dirPath}/hackmd-styles.mjs`));
-const agentJSFile = fs.readFileSync(path.resolve(__dirname, `${dirPath}/hackmd-agent.mjs`));
+const stylesJSFile = fs.readFileSync(path.resolve(__dirname, `${dirPath}/hackmd-styles.js`));
+const agentJSFile = fs.readFileSync(path.resolve(__dirname, `${dirPath}/hackmd-agent.js`));
 const stylesCSSFile = fs.readFileSync(path.resolve(__dirname, `${dirPath}/style.css`));
 const stylesCSSFile = fs.readFileSync(path.resolve(__dirname, `${dirPath}/style.css`));
 
 
 // export to app as string
 // export to app as string
-module.exports = {
+const hackmdFiles = {
   stylesJS: stylesJSFile.toString(),
   stylesJS: stylesJSFile.toString(),
   agentJS: agentJSFile.toString(),
   agentJS: agentJSFile.toString(),
   stylesCSS: stylesCSSFile.toString().replace(/(\r\n|\n|\r)/gm, ''), // https://stackoverflow.com/questions/10805125/how-to-remove-all-line-breaks-from-a-string
   stylesCSS: stylesCSSFile.toString().replace(/(\r\n|\n|\r)/gm, ''), // https://stackoverflow.com/questions/10805125/how-to-remove-all-line-breaks-from-a-string
 };
 };
+export default hackmdFiles;

+ 2 - 0
packages/hackmd/tsconfig.json

@@ -2,6 +2,8 @@
   "$schema": "http://json.schemastore.org/tsconfig",
   "$schema": "http://json.schemastore.org/tsconfig",
   "extends": "../../tsconfig.base.json",
   "extends": "../../tsconfig.base.json",
   "compilerOptions": {
   "compilerOptions": {
+    "isolatedModules": false,
+
     "baseUrl": ".",
     "baseUrl": ".",
     "paths": {
     "paths": {
     }
     }

+ 9 - 2
packages/hackmd/vite.config.js

@@ -11,12 +11,19 @@ export default defineConfig({
     outDir: 'dist',
     outDir: 'dist',
     lib: {
     lib: {
       entry: [
       entry: [
-        'src/hackmd-styles.js',
+        'src/index.ts',
+        'src/hackmd-styles.ts',
         'src/hackmd-agent.js',
         'src/hackmd-agent.js',
         'src/style.scss',
         'src/style.scss',
       ],
       ],
       name: 'hackmd-libs',
       name: 'hackmd-libs',
-      formats: ['es'],
+      formats: ['es', 'cjs'],
+    },
+    rollupOptions: {
+      external: [
+        'node:fs',
+        'node:path',
+      ],
     },
     },
   },
   },
 });
 });