Skip to content

Commit

Permalink
fix: apache-composer versus webpack fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
starpit committed Apr 17, 2019
1 parent 5e2ac39 commit 21e55b5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/kui-builder/dist/webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module.exports = {
'dns', // modules/openwhisk/node_modules/retry/example/dns.js
'tls', // needed by request
'tap', // wskflow
'request', // needed by some apache-composer samples
'babel-core/register', // wskflow
'aws-sdk', // wskflow
'node-pty', // bash-like
Expand Down Expand Up @@ -191,7 +192,7 @@ module.exports = {
// end of ignore-loader
//
// { test: /\.js$/, use: ['source-map-loader'], enforce: 'pre' },
{ test: /samples\/.*\.js$/, use: 'raw-loader' }, // don't try to parse out sample input, e.g. for dependencies
// { test: /samples\/.*\.js$/, use: 'raw-loader' }, // don't try to parse out sample input, e.g. for dependencies
{ test: /\.js.map$/, use: 'ignore-loader' },
{ test: /\.py$/, use: 'file-loader' },
{ test: /\.ico$/, use: 'file-loader' },
Expand Down
12 changes: 9 additions & 3 deletions plugins/plugin-apache-composer/src/lib/utility/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const sourceToComposition = ({ inputFile, name = '', recursive = false })
return loadSourceCode(inputFile, localCodePath) // check inputfile extension and existence and then return the source code
.then(sourceCode => loadComposition(inputFile, sourceCode)) // check before parse by composer and give users more freedom on source input
.then(composition => resolve(compileComposition(composition, name))) // parse and compile composition and get {composition, ast, version} object
.catch(err => reject(err))
.catch(reject)
})

const loadSourceCode = (inputFile, localCodePath) => new Promise(async (resolve, reject) => {
Expand All @@ -60,7 +60,8 @@ const loadSourceCode = (inputFile, localCodePath) => new Promise(async (resolve,
} else {
debug('readFile for webpack', localCodePath)
try {
const data = await import('@kui-shell/plugin-apache-composer/lib' + localCodePath.replace(/^\/?plugins\/plugin-apache-composer\/lib/, ''))
const data = await import('@kui-shell/plugin-apache-composer/samples' + localCodePath.replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1'))
debug('readFile for webpack done', data)
resolve(data)
} catch (err) {
console.error(err)
Expand All @@ -72,7 +73,10 @@ const loadSourceCode = (inputFile, localCodePath) => new Promise(async (resolve,
})

export const loadComposition = (inputFile, originalCode?, localCodePath?) => {
if (inBrowser() && originalCode) return originalCode
if (inBrowser() && originalCode) {
debug('loadComposition for webpack', originalCode)
return originalCode
}

const localSourcePath = localCodePath || findFile(expandHomeDir(inputFile))

Expand Down Expand Up @@ -230,6 +234,8 @@ export const implicitInputFile = (inputFile, name) => {
*
*/
export const compileComposition = (composition, name) => {
debug('compileComposition', composition)

let result
try {
result = Composer.parse(composition)
Expand Down
5 changes: 3 additions & 2 deletions plugins/plugin-bash-like/src/pty/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import * as fs from 'fs'
import { promisify } from 'util'
import { createServer } from 'net'
import { dirname, join } from 'path'
import { exec, spawn } from 'child_process'

Expand All @@ -35,7 +34,9 @@ type ExitHandler = (exitCode: number) => Promise<void>
* Allocate a port
*
*/
const getPort = (): Promise<number> => new Promise((resolve, reject) => {
const getPort = (): Promise<number> => new Promise(async (resolve, reject) => {
const { createServer } = await import('net')

const iter = () => {
const port = portRange
portRange += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ const defaultPlaceholderFn = ({ kind = 'nodejs:default', template }) => {
// otherwise, we will open the editor showing a template file
return new Promise((resolve, reject) => {
const readViaImport = () => {
debug('readViaImport', findFile(template), findFile(template).replace(/^plugins\/plugin-apache-composer\/samples\/@demos/, ''))
resolve(require('raw-loader!@kui-shell/plugin-apache-composer/samples/@demos' + findFile(template).replace(/^plugins\/plugin-apache-composer\/samples\/@demos/, '')))
debug('readViaImport', findFile(template), findFile(template).replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1'))
resolve(require('raw-loader!@kui-shell/plugin-apache-composer/samples' + findFile(template).replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1')).default)
}

const readViaFilesystem = () => {
Expand Down Expand Up @@ -325,7 +325,7 @@ export const newAction = ({ prequire, cmd = 'new', type = 'actions', _kind = def

// generate AST, if we were given a template
const compile = () => type === 'compositions' && options.template
? inBrowser() ? import('@kui-shell/plugin-apache-composer/samples/@demos' + findFile(options.template).replace(/^plugins\/plugin-apache-composer\/samples\/@demos/, ''))
? inBrowser() ? import('@kui-shell/plugin-apache-composer/samples' + findFile(options.template).replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1'))
: generateAST(code, options.template, options.kind || defaults.kind)
: Promise.resolve()

Expand Down
4 changes: 3 additions & 1 deletion plugins/plugin-wskflow/src/lib/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const registration: PluginRegistration = (commandTree, prequire) => {
if (filepath.indexOf('@') >= 0) {
debug('readFile for webpack, built-in', filepath)
try {
const data = await import('@kui-shell/plugin-apache-composer/lib' + filepath.replace(/^\/?plugins\/plugin-apache-composer\/lib/, ''))
const data = await import('raw-loader!@kui-shell/plugin-apache-composer/samples' + filepath.replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1'))

resolve(data)
} catch (err) {
Expand Down Expand Up @@ -131,6 +131,8 @@ const registration: PluginRegistration = (commandTree, prequire) => {

// create a fake action/entity record
const formatForUser = (mode: string) => async (composition: ICompositionWithCode) => {
debug('formatForUser', composition)

const { ast } = composition
const code = await readFile(input)
// pass through cli options for the wskflow renderer
Expand Down

0 comments on commit 21e55b5

Please sign in to comment.