diff --git a/.changeset/few-singers-pump.md b/.changeset/few-singers-pump.md new file mode 100644 index 000000000000..489c451e0924 --- /dev/null +++ b/.changeset/few-singers-pump.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-node': patch +--- + +Convert to ESM diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index fc9fcd9b335a..e562d4dca90c 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -1,9 +1,9 @@ -'use strict'; +import { copyFileSync } from 'fs'; +import { dirname, join } from 'path'; +import { fileURLToPath } from 'url'; -const fs = require('fs'); -const { join } = require('path'); - -module.exports = async function adapter(builder) { +export default async function adapter(builder) { + const dir = dirname(fileURLToPath(import.meta.url)); const out = 'build'; // TODO implement adapter options builder.log.minor('Writing client application...'); @@ -14,10 +14,10 @@ module.exports = async function adapter(builder) { builder.log.minor('Building server'); builder.copy_server_files(out); - fs.copyFileSync(`${__dirname}/files/server.js`, `${out}/index.js`); + copyFileSync(`${dir}/files/server.js`, `${out}/index.js`); builder.log.minor('Prerendering static pages...'); await builder.prerender({ dest: `${out}/prerendered` }); -}; +}