Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

1.0.1 (Unreleased)
------------------

- Update the export_target production and usage of working_dir to be
inline with what is expected by ``calmjs-3.1.0``. [
`#2 <https://github.com/calmjs/calmjs.webpack/issues/2>`_
]

1.0.0 (2018-01-12)
------------------

Expand Down
20 changes: 16 additions & 4 deletions src/calmjs/webpack/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"""

import logging
from os.path import join
from os.path import realpath

from calmjs.toolchain import Spec
from calmjs.toolchain import spec_update_sourcepath_filter_loaderplugins

from calmjs.toolchain import BUILD_DIR
from calmjs.toolchain import CALMJS_MODULE_REGISTRY_NAMES
from calmjs.toolchain import CALMJS_LOADERPLUGIN_REGISTRY_NAME
from calmjs.toolchain import WORKING_DIR

from calmjs.toolchain import EXPORT_TARGET
from calmjs.toolchain import GENERATE_SOURCE_MAP
Expand Down Expand Up @@ -194,13 +197,20 @@ def create_spec(

working_dir = working_dir if working_dir else default_toolchain.join_cwd()

# Normalize export_target and raw webpack.output.library
# Note that webpack_output_library is not directly assigned at this
# moment.
if export_target is None:
# Take the final package name for now...
if package_names:
export_target = package_names[-1] + '.js'
computed_output_library = package_names[-1]
else:
export_target = 'calmjs.webpack.export.js'
logger.debug("'export_target' autoconfig to '%s'", export_target)
computed_output_library = 'calmjs.webpack.export'
export_target = realpath(
join(working_dir, computed_output_library + '.js'))
logger.info("'export_target' is now set to '%s'", export_target)
else:
computed_output_library = export_target[:-3]

spec = Spec()

Expand All @@ -227,6 +237,7 @@ def create_spec(
)

spec[BUILD_DIR] = build_dir
spec[WORKING_DIR] = working_dir
spec[CALMJS_MODULE_REGISTRY_NAMES] = source_registries
spec[EXPORT_TARGET] = export_target
spec[SOURCE_PACKAGE_NAMES] = package_names
Expand Down Expand Up @@ -283,7 +294,7 @@ def create_spec(
# currently calmjs_compat mode assumes that it must be "umd".
if webpack_output_library is True:
if webpack_entry_point == DEFAULT_BOOTSTRAP_EXPORT:
spec[WEBPACK_OUTPUT_LIBRARY] = export_target[:-3]
spec[WEBPACK_OUTPUT_LIBRARY] = computed_output_library
logger.info(
"calmjs_compat is disabled; webpack.output.library "
"automatically set to '%s', derived from input package "
Expand All @@ -292,6 +303,7 @@ def create_spec(
spec[WEBPACK_OUTPUT_LIBRARY]
)
else:
# set to entry_point as that is defined.
spec[WEBPACK_OUTPUT_LIBRARY] = webpack_entry_point
logger.info(
"calmjs_compat is disabled; webpack.output.library "
Expand Down
6 changes: 4 additions & 2 deletions src/calmjs/webpack/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def init_argparser_working_dir(self, argparser):
super(WebpackRuntime, self).init_argparser_working_dir(
argparser,
explanation=(
'for this tool it will be used as the base directory to '
'find source files declared for bundling; '
'for this tool it will be used as the base directory for '
'locating the node_modules for the declared bundled source '
'files, and as the base directory for export_target and '
'build_dir paths; '
),
)

Expand Down
79 changes: 72 additions & 7 deletions src/calmjs/webpack/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
import unittest
import os
from os.path import join

from calmjs.toolchain import Spec
from calmjs.utils import pretty_logging
Expand All @@ -8,6 +10,8 @@
from calmjs.webpack.cli import compile_all

from calmjs.testing.mocks import StringIO
from calmjs.testing.utils import remember_cwd
from calmjs.testing.utils import mkdtemp


class CliTestCase(unittest.TestCase):
Expand All @@ -16,6 +20,11 @@ class CliTestCase(unittest.TestCase):
in the toolchain and/or the integration tests.
"""

def setUp(self):
remember_cwd(self)
self.cwd = mkdtemp(self)
os.chdir(self.cwd)

def test_create_spec_empty(self):
with pretty_logging(stream=StringIO()) as stream:
spec = create_spec([])
Expand All @@ -27,7 +36,9 @@ def test_create_spec_empty(self):
"'__calmjs__'", stream.getvalue()
)
self.assertTrue(isinstance(spec, Spec))
self.assertEqual(spec['export_target'], 'calmjs.webpack.export.js')
self.assertEqual(spec['working_dir'], self.cwd)
self.assertEqual(spec['export_target'], join(
self.cwd, 'calmjs.webpack.export.js'))
self.assertEqual(spec['calmjs_module_registry_names'], [])
self.assertIn('webpack_externals', spec)
self.assertEqual(spec['webpack_output_library'], '__calmjs__')
Expand Down Expand Up @@ -74,7 +85,8 @@ def test_create_spec_with_calmjs_webpack(self):
with pretty_logging(stream=StringIO()) as stream:
spec = create_spec(['calmjs.webpack'])
self.assertTrue(isinstance(spec, Spec))
self.assertEqual(spec['export_target'], 'calmjs.webpack.js')
self.assertEqual(spec['export_target'], join(
self.cwd, 'calmjs.webpack.js'))
self.assertEqual(spec.get('webpack_entry_point'), '__calmjs__')
self.assertEqual(
spec['calmjs_module_registry_names'], ['calmjs.module'])
Expand All @@ -87,11 +99,38 @@ def test_create_spec_with_calmjs_webpack(self):
"sourcepaths", log,
)

def test_create_spec_with_calmjs_webpack_manual_working_dir(self):
working_dir = mkdtemp(self)
with pretty_logging(stream=StringIO()) as stream:
spec = create_spec(
['calmjs.webpack'],
working_dir=working_dir
)

self.assertTrue(isinstance(spec, Spec))
self.assertEqual(spec['export_target'], join(
working_dir, 'calmjs.webpack.js'))
log = stream.getvalue()
self.assertIn("'export_target' is now set to", log)

def test_create_spec_with_calmjs_webpack_manual_export_target(self):
with pretty_logging(stream=StringIO()) as stream:
spec = create_spec(
['calmjs.webpack'],
export_target='somewhere.js',
)

self.assertTrue(isinstance(spec, Spec))
self.assertEqual(spec['export_target'], 'somewhere.js')
log = stream.getvalue()
self.assertNotIn("'export_target' autoconfig to", log)

def test_create_spec_with_calmjs_webpack_entry_point_only(self):
with pretty_logging(stream=StringIO()) as stream:
spec = create_spec(['calmjs.webpack'], webpack_entry_point='entry')
self.assertTrue(isinstance(spec, Spec))
self.assertEqual(spec['export_target'], 'calmjs.webpack.js')
self.assertEqual(spec['export_target'], join(
self.cwd, 'calmjs.webpack.js'))
self.assertEqual(
spec['calmjs_module_registry_names'], ['calmjs.module'])
self.assertEqual(
Expand Down Expand Up @@ -120,7 +159,8 @@ def test_create_spec_with_calmjs_webpack_no_bootstrap(self):
with pretty_logging(stream=StringIO()) as stream:
spec = create_spec(['calmjs.webpack'], calmjs_compat=False)
self.assertTrue(isinstance(spec, Spec))
self.assertEqual(spec['export_target'], 'calmjs.webpack.js')
self.assertEqual(spec['export_target'], join(
self.cwd, 'calmjs.webpack.js'))
self.assertEqual(
spec['calmjs_module_registry_names'], ['calmjs.module'])
self.assertEqual(
Expand All @@ -140,7 +180,8 @@ def test_create_spec_with_calmjs_webpack_no_registry(self):
spec = create_spec(
['calmjs.webpack'], source_registry_method='none')
self.assertTrue(isinstance(spec, Spec))
self.assertEqual(spec['export_target'], 'calmjs.webpack.js')
self.assertEqual(spec['export_target'], join(
self.cwd, 'calmjs.webpack.js'))
self.assertEqual(
spec['calmjs_module_registry_names'], [])
self.assertEqual(
Expand All @@ -157,7 +198,8 @@ def test_create_spec_with_calmjs_webpack_manual_source(self):
spec = create_spec(
['calmjs.webpack'], source_registries=['calmjs.module.tests'])
self.assertTrue(isinstance(spec, Spec))
self.assertEqual(spec['export_target'], 'calmjs.webpack.js')
self.assertEqual(spec['export_target'], join(
self.cwd, 'calmjs.webpack.js'))
self.assertEqual(
spec['calmjs_module_registry_names'], ['calmjs.module.tests'])
self.assertEqual(
Expand Down Expand Up @@ -222,6 +264,28 @@ def test_create_spec_with_calmjs_webpack_output_library_disable(self):
self.assertEqual(spec['webpack_entry_point'], 'custom_entry')
self.assertNotIn('webpack_output_library', spec)

def test_create_spec_with_calmjs_webpack_output_library_enabled(self):
with pretty_logging(stream=StringIO()) as stream:
spec = create_spec(
['calmjs.webpack'], calmjs_compat=False,
webpack_output_library=True,
)
log = stream.getvalue()
self.assertNotIn(
"webpack_entry_point is ignored; set calmjs_compat to false "
"to enable manual webpack.entry specification", log
)
self.assertNotIn(
"webpack.output.library is disabled; it will be unset.", log)
self.assertIn(
"calmjs_compat is disabled; webpack.output.library "
"automatically set to 'calmjs.webpack', derived from input "
"package names and export filename", log
)
# note that this is probably an invalid value.
self.assertEqual(spec['webpack_entry_point'], '__calmjs__')
self.assertEqual(spec['webpack_output_library'], 'calmjs.webpack')

def test_toolchain_empty(self):
# dict works well enough as a null toolchain
with pretty_logging(stream=StringIO()) as stream:
Expand All @@ -230,4 +294,5 @@ def test_toolchain_empty(self):
self.assertNotIn('packages []', stream.getvalue())
self.assertIn('no packages specified', stream.getvalue())
self.assertTrue(isinstance(spec, Spec))
self.assertEqual(spec['export_target'], 'calmjs.webpack.export.js')
self.assertEqual(spec['export_target'], join(
self.cwd, 'calmjs.webpack.export.js'))
9 changes: 6 additions & 3 deletions src/calmjs/webpack/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ def test_cli_create_spec(self):
with pretty_logging(stream=StringIO()):
spec = cli.create_spec(
['site'], source_registries=(self.registry_name,))
self.assertEqual(spec['export_target'], 'site.js')
self.assertEqual(
spec['export_target'], join(self._env_root, 'site.js'))

def test_cli_compile_all_site(self):
# create a new working directory to install our current site
Expand Down Expand Up @@ -763,8 +764,10 @@ def test_runtime_cli_help_text(self):
'defaults to last ${package_name}.js ', out)
self.assertIn(
'--working-dir <working_dir> the working directory; '
'for this tool it will be used as the base directory to '
'find source files declared for bundling; ', out)
'for this tool it will be used as the base directory for '
'locating the node_modules for the declared bundled source '
'files, and as the base directory for export_target and '
'build_dir paths; ', out)
self.assertIn('default is current working directory', out)

def test_runtime_cli_compile_explicit_missing(self):
Expand Down