Skip to content

Commit

Permalink
fix: inline svelte-app-utils lib (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jthegedus authored Mar 4, 2021
1 parent 4ad0ea9 commit 6f79964
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
30 changes: 19 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"main": "dist/index.js",
"version": "0.3.2",
"dependencies": {
"@sveltejs/app-utils": "1.0.0-next.0",
"joi": "^17.3.0"
"@sveltejs/app-utils": "^1.0.0-next.1",
"joi": "^17.4.0"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
Expand All @@ -37,6 +37,7 @@
"husky": "^5.0.8",
"microbundle": "^0.13.0",
"rewire": "^5.0.0",
"rimraf": "^3.0.2",
"semantic-release": "^17.4.0",
"xo": "^0.37.1"
},
Expand All @@ -48,7 +49,11 @@
"fix": "xo --fix",
"test": "xo && ava",
"dev": "microbundle watch --target node",
"build": "microbundle --target node && mkdir -p dist/files && cp -p src/files/cloud_run_package.json dist/files/package.json && cp -p src/files/handler.js dist/files/handler.js"
"prebuild": "rimraf dist",
"build:cli": "microbundle --target node --external none",
"build:handler": "microbundle --target node --format es,cjs --external none --entry src/files/handler.js --output dist/files/handler.js",
"build:cloudrun": "mkdir -p dist/files && cp -p src/files/cloud_run_package.json dist/files/package.json",
"build": "npm run build:cli && npm run build:handler && npm run build:cloudrun"
},
"engines": {
"node": ">=10.0.0"
Expand Down
10 changes: 7 additions & 3 deletions src/files/handler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const {get_body: getBody} = require('@sveltejs/app-utils/http');
const app = require('./app.cjs');
// Deps - inlined
import {get_body as getBody} from '@sveltejs/app-utils/http';

exports.sveltekitServer = async (request, response) => {
const app = require('./app.js');

const svelteKit = async (request, response) => {
const {pathname, query = ''} = new URL(
request.url || '',
`https://${request.headers.host}/`
Expand All @@ -23,3 +25,5 @@ exports.sveltekitServer = async (request, response) => {

return response.writeHead(404).end();
};

export default svelteKit;
13 changes: 8 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const {existsSync, readFileSync} = require('fs');
// Deps - installed
const fs = require('fs');
const path = require('path');
const {copy} = require('@sveltejs/app-utils/files');
const Joi = require('joi');

// Deps - inlined
import {copy} from '@sveltejs/app-utils/files';

// If valid config returns the config as JS Object, else throws error
function validateFirebaseConfig(firebaseJson, hostingSite, sourceRewriteMatch) {
const schema = Joi.object().keys({
Expand Down Expand Up @@ -118,9 +121,9 @@ for either a Function or Cloud Run service.
}

function getFile(filepath) {
if (existsSync(filepath)) {
if (fs.existsSync(filepath)) {
try {
return readFileSync(filepath, 'utf-8');
return fs.readFileSync(filepath, 'utf-8');
} catch (error) {
throw new Error(`Error reading ${filepath}: ${error.message}`);
}
Expand Down Expand Up @@ -194,7 +197,7 @@ async function adapter(builder, {
.replace(/\W/g, '')
.concat('Server');
if (
existsSync(functionsIndexPath) &&
fs.existsSync(functionsIndexPath) &&
!getFile(functionsIndexPath).includes(`${cloudFunctionName} =`)
) {
builder.log.warn(
Expand Down

0 comments on commit 6f79964

Please sign in to comment.